@stalfh233/omc-cli 0.6.65 → 0.6.67

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/graph.js CHANGED
@@ -6,6 +6,7 @@ import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "./json-column.js";
6
6
  import { ENDPOINTS } from "./endpoints.js";
7
7
  import { applicationResolutionOf, flattenTreeRows, resolveApplicationScope, sha256 } from "./support.js";
8
8
  import { wireCall, wireRows } from "./wire.js";
9
+ import { walkConditionLeaves } from "./lanes/rule-graph.js";
9
10
  /**
10
11
  * `node:sqlite` must stay OUT of the CLI's startup module graph: a static
11
12
  * import emits the ExperimentalWarning during ESM linking, before any user
@@ -32,7 +33,9 @@ function nodeSqlite() {
32
33
  * rows → businessRuleGet per row id — the exact wire reads rule.references
33
34
  * makes; rows from the list face are current, so no stale-row double-read);
34
35
  * - edges are api-fact only, extracted with rule.references' matching
35
- * semantics (service/model/field — see extractReferenceEdges);
36
+ * semantics (service/model/field) plus, since r72g, rule CONDITION leaves
37
+ * (via rule.condition — the online face's blind spot; see
38
+ * extractReferenceEdges);
36
39
  * - fail-closed completeness: every swallowed read/parse failure is a recorded
37
40
  * gap; a zero-hit answer over a gapped index never claims "no references";
38
41
  * - derived locator, never authority: results are candidate pointers; plan /
@@ -46,7 +49,9 @@ function nodeSqlite() {
46
49
  * staleness is handled by reporting pulledAt + identity, refreshed by an
47
50
  * explicit re-pull (no incremental watermarks, no write-back hooks).
48
51
  */
49
- export const GRAPH_SCHEMA_VERSION = "7";
52
+ // r72g(2026-11-17):规则条件叶子入边(via rule.condition)——v7 索引没有这类
53
+ // 边,若不升版,旧库会在新覆盖声明下静默漏答「谁的条件引用了字段 X」。
54
+ export const GRAPH_SCHEMA_VERSION = "8";
50
55
  const STALE_LOCK_MS = 15 * 60 * 1000;
51
56
  export const DEFAULT_PULL_CONCURRENCY = 16;
52
57
  export const MAX_PULL_CONCURRENCY = 32;
@@ -234,12 +239,59 @@ export class GraphIndexAmbiguousError extends GraphIndexError {
234
239
  }
235
240
  }
236
241
  /**
237
- * Extract api-fact reference edges from one rule's stored node graph. The
238
- * matching mirrors `rule.references` exactly (businessrule.ts) so the index and
239
- * the live scan answer the same question; anything rule.references cannot see
240
- * (condition leaves, datarules — its v1 boundary) is equally invisible here.
242
+ * Condition-container keys on a rule node whose leaves reference fields. The
243
+ * nested walk itself is `walkConditionLeaves` (rule-graph.ts) — the same wire
244
+ * contract the dry lint validates, so extractor and linter can never drift on
245
+ * what a "condition leaf" is.
241
246
  */
242
- export function extractReferenceEdges(schemaCode, ruleCode, nodes) {
247
+ const RULE_CONDITION_NODE_CONTAINERS = ["filterCondition", "filterSubCondition", "dataCondition", "execConditionGroups", "targetConditionGroups", "exitConditionGroups", "findMainData", "sourceConditionGroups"];
248
+ /** `{field}` tokens inside a serialized condition value (EXPRESSION formulas; the platform's own field-reference syntax, cf. extractDataRuleEdges). */
249
+ function conditionValueTokens(value) {
250
+ let text;
251
+ try {
252
+ text = JSON.stringify(value ?? null);
253
+ }
254
+ catch {
255
+ return [];
256
+ }
257
+ const tokens = new Set();
258
+ for (const match of text.matchAll(/\{([A-Za-z0-9_.-]+)\}/g))
259
+ tokens.add(match[1]);
260
+ return [...tokens];
261
+ }
262
+ /**
263
+ * Date-dynamic condition value types whose `currentSchemaDataItem` is a day/
264
+ * range OFFSET ("0"=今天、"-7"=7天前、"thisWeek"…— DateFieldFilter parses it
265
+ * with Integer.parseInt), not a field code (live noise: r72g rebuild produced
266
+ * a `field 0` edge from meeting_room_booking/mrbDailyOvertime). The TARGET
267
+ * side of such leaves is still a real field and stays extracted.
268
+ */
269
+ const CONDITION_CURRENT_SIDE_NOT_FIELD_TYPES = new Set(["today", "specifyDate", "specifyRange", "dynamicRange"]);
270
+ /**
271
+ * Extract api-fact reference edges from one rule's stored node graph.
272
+ *
273
+ * `rule.references`(businessrule.ts,在线面)的匹配语义保持镜像——service/
274
+ * model/field 三类边同问同答。r72g(2026-11-17)起本函数 additionally 抽
275
+ * **规则条件叶子**(在线面仍不扫,是两面的差异点,见 GRAPH_COVERAGE.crossFace):
276
+ * 探针为撑「业务规则零引用 amount」的否定结论逐条 rule.get 看条件(9 次),
277
+ * 条件叶子入边后 `graph references field` 一次可答。
278
+ *
279
+ * 归属规则(edges.schemaCode = 被引用字段的**宿主**模型,与 r58 `schema.field`
280
+ * 精确查询的语义一致;证据:真机 mcc_supplier_assessment 三规则 + crm_contract
281
+ * daily_expiry_scan 的 schedulerSetting,2026-11-17 抓取):
282
+ * - 叶 `currentSchemaDataItem`(DYNAMIC 过滤来源 / BRANCH 出口左值)→ 承载模型;
283
+ * - 叶 `targetSchemaDataItem`(过滤目标字段)→ 条件作用的模型:UPDATE/DELETE 的
284
+ * filterCondition 在 targetObjectCode 的行上匹配(无 target = 自更新 → 承载
285
+ * 模型);QUERY 的 targetConditionGroups 作用在 targetSchemaCode(可带
286
+ * `.sheetCode`,取前段);其余节点族(CREATE findMainData/filterCondition、
287
+ * BIZ_ACTION execConditionGroups、ASSIGN dataCondition…)按承载模型;
288
+ * - 定时规则 `schedulerSetting.filterConditionGroups`(GET_LIST 扫描本模型)→
289
+ * 承载模型,nodeCode=SCHEDULER(该族图的入口系统节点);
290
+ * - 叶 `value` 里的 `{字段}` 模板(EXPRESSION 公式等)→ 与该容器的
291
+ * targetSchemaDataItem 同模型(容器归属,没有证据细分到 DYNAMIC 侧);
292
+ * - route 上的条件容器(证据上条件都在节点上,防御性兜底)→ 承载模型。
293
+ */
294
+ export function extractReferenceEdges(schemaCode, ruleCode, nodes, routes = [], schedulerSetting = undefined) {
243
295
  const edges = [];
244
296
  const push = (kind, code, node, via) => {
245
297
  if (code === "")
@@ -254,6 +306,26 @@ export function extractReferenceEdges(schemaCode, ruleCode, nodes) {
254
306
  via,
255
307
  });
256
308
  };
309
+ const pushCondition = (code, ownerSchema, nodeCode, seen) => {
310
+ if (code === "")
311
+ return;
312
+ const dedupeKey = `${ownerSchema}/${code}`;
313
+ if (seen.has(dedupeKey))
314
+ return;
315
+ seen.add(dedupeKey);
316
+ edges.push({ kind: "field", code, schemaCode: ownerSchema, ruleCode, nodeCode, nodeType: "rule-condition", via: "rule.condition" });
317
+ };
318
+ // One leaf → up to three field references: the CURRENT-side source (host
319
+ // model; skipped for date-dynamic leaves where it is an offset, not a code),
320
+ // the TARGET-side field (the model the condition acts on), and {field}
321
+ // formula tokens in the value (same model as the target side).
322
+ const leafVisitor = (targetSideSchema, nodeCode, seen) => (leaf) => {
323
+ if (!CONDITION_CURRENT_SIDE_NOT_FIELD_TYPES.has(String(leaf.ruleValueType ?? "")))
324
+ pushCondition(String(leaf.currentSchemaDataItem ?? ""), schemaCode, nodeCode, seen);
325
+ pushCondition(String(leaf.targetSchemaDataItem ?? ""), targetSideSchema, nodeCode, seen);
326
+ for (const token of conditionValueTokens(leaf.value))
327
+ pushCondition(token, targetSideSchema, nodeCode, seen);
328
+ };
257
329
  for (const node of nodes) {
258
330
  const mapping = node.methodMapping;
259
331
  if (node.nodeType === "BIZ_ACTION" && mapping) {
@@ -274,6 +346,40 @@ export function extractReferenceEdges(schemaCode, ruleCode, nodes) {
274
346
  push("field", String(row.bizCode), node, label);
275
347
  }
276
348
  }
349
+ // r72g: condition leaves on this node (deduped per node — a leaf repeating
350
+ // `id` on both sides of an identity filter is one edge per side-model).
351
+ const nodeType = String(node.nodeType ?? "");
352
+ const nodeCode = String(node.nodeCode ?? "");
353
+ const queriedSchema = String(node.targetSchemaCode ?? "").split(".")[0] ?? "";
354
+ const actingModel = queriedSchema || ((nodeType === "UPDATE" || nodeType === "DELETE") ? String(node.targetObjectCode ?? "") : "") || schemaCode;
355
+ const seen = new Set();
356
+ for (const key of RULE_CONDITION_NODE_CONTAINERS) {
357
+ if (node[key] === undefined || node[key] === null)
358
+ continue;
359
+ walkConditionLeaves(node[key], leafVisitor(actingModel, nodeCode, seen));
360
+ }
361
+ }
362
+ // Routes: evidenced condition homes are all node-level, but a stored route
363
+ // carrying a condition container must not silently vanish — walk it too.
364
+ for (const route of routes) {
365
+ const routeCode = `${String(route.preNode ?? "")}->${String(route.postNode ?? "")}`;
366
+ walkConditionLeaves(route, leafVisitor(schemaCode, routeCode, new Set()));
367
+ }
368
+ // Scheduler rules (bizRuleType=2): the scan filter lives rule-level in
369
+ // schedulerSetting.filterConditionGroups, not on any node. GET_LIST scans the
370
+ // hosting model, so both leaf sides attribute to it.
371
+ let scheduler = schedulerSetting;
372
+ if (typeof scheduler === "string") {
373
+ try {
374
+ scheduler = JSON.parse(scheduler);
375
+ }
376
+ catch {
377
+ scheduler = undefined;
378
+ }
379
+ }
380
+ if (scheduler && typeof scheduler === "object" && !Array.isArray(scheduler)) {
381
+ const settings = scheduler;
382
+ walkConditionLeaves(settings.filterConditionGroups, leafVisitor(schemaCode, "SCHEDULER", new Set()));
277
383
  }
278
384
  return edges;
279
385
  }
@@ -510,6 +616,8 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
510
616
  gaps.push({ kind: "rule-graph-parse", ref: `${schemaCode}/${ruleCode}` });
511
617
  return;
512
618
  }
619
+ const routes = decodeJsonColumn(record.route, JSON_COLUMN_NULL_COALESCE);
620
+ const schedulerSetting = decodeJsonColumn(record.schedulerSetting, JSON_COLUMN_NULL_COALESCE);
513
621
  rules.push({
514
622
  schemaCode,
515
623
  ruleCode,
@@ -518,9 +626,10 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
518
626
  status: typeof record.status === "string" ? record.status : null,
519
627
  defaultRule: typeof record.defaultRule === "boolean" ? record.defaultRule : null,
520
628
  rowId: ruleId,
521
- graphSha256: sha256({ nodes, routes: decodeJsonColumn(record.route, JSON_COLUMN_NULL_COALESCE) }),
629
+ graphSha256: sha256({ nodes, routes }),
522
630
  });
523
- edges.push(...extractReferenceEdges(schemaCode, ruleCode, nodes).map((edge) => ({ ...edge, applicationCode })));
631
+ // r72g:条件叶子(node 容器 + route 兜底 + 定时规则 schedulerSetting)一并入边。
632
+ edges.push(...extractReferenceEdges(schemaCode, ruleCode, nodes, Array.isArray(routes) ? routes : [], schedulerSetting).map((edge) => ({ ...edge, applicationCode })));
524
633
  }
525
634
  catch (error) {
526
635
  gaps.push({ kind: "rule-get", ref: `${schemaCode}/${ruleCode}`, note: error instanceof Error ? error.message : String(error) });
@@ -886,17 +995,22 @@ function openGraphIndex(selector = {}) {
886
995
  * 分散定义就会被漏掉一处(MCP 面第一版就漏了)。
887
996
  */
888
997
  export const GRAPH_COVERAGE = Object.freeze({
998
+ // r72g(2026-11-17):businessrule 面从「结构引用」扩到「条件叶子」——规则
999
+ // nodeGraph 各条件容器(filterCondition/targetConditionGroups/
1000
+ // exitConditionGroups/dataCondition/…)+ 定时规则 schedulerSetting.
1001
+ // filterConditionGroups 的字段引用以 rule.condition 边入索引;schema 升到
1002
+ // 8 强制旧库重拉,避免旧索引在新声明下静默漏答。
889
1003
  scanned: Object.freeze(["businessrule", "datarule", "listview"]),
890
- notScanned: Object.freeze(["form", "workflow.permissions", "workflow.bindings", "onlinejs", "rule.conditions"]),
1004
+ notScanned: Object.freeze(["form", "workflow.permissions", "workflow.bindings", "onlinejs"]),
891
1005
  answerable: Object.freeze(["businessrule", "datarule", "listview"]),
892
1006
  mustCheckManually: Object.freeze([
893
1007
  { surface: "form", why: "表单控件关联未扫描,可能仍引用目标字段", how: "omc call form.get --args '{\"schemaCode\":\"<x>\"}'" },
894
1008
  { surface: "workflow.permissions", why: "流程权限未扫描,无法判断谁能发起/操作", how: "omc call workflow.get --args '{\"schemaCode\":\"<x>\"}'" },
895
1009
  { surface: "workflow.bindings", why: "流程规则绑定未扫描,规则删除可能留下绑定", how: "omc call workflow.get --args '{\"schemaCode\":\"<x>\"}'" },
896
1010
  { surface: "onlinejs", why: "在线 JS 可能通过字符串引用字段", how: "omc call onlinejs.get --args '{\"schemaCode\":\"<x>\"}'" },
897
- { surface: "rule.conditions", why: "规则条件叶子未扫描,命中可能不完整", how: "omc call rule.list --args '{\"schemaCode\":\"<x>\"}' 后人工检查条件公式" },
898
1011
  ]),
899
1012
  note: "零命中/全零 totals 只代表 scanned 面没有命中;notScanned 面(尤其 form 与 workflow.permissions)未扫描,不可据此判定可安全删除或无影响",
1013
+ crossFace: "在线对照面:`omc call rule.references`(实时,仅 businessrule,不含条件叶子);本索引(离线快照,businessrule+datarule+listview,且含规则条件叶子 rule.condition 边)——条件里的字段引用离线一次可答,在线面要 rule.get 逐条看",
900
1014
  });
901
1015
  /**
902
1016
  * Zero-hit disambiguation (2026-10-31 capability-test friction, hit twice in
@@ -934,12 +1048,70 @@ function splitScopedCode(code) {
934
1048
  return null; // 只认一层 a.b
935
1049
  return { schemaCode, code: bare };
936
1050
  }
1051
+ /** r72g:点前段是否是索引里的已知 schema(models 实体表优先,fields/rules/edges 兜底)。 */
1052
+ function schemaKnownToIndex(db, schemaCode) {
1053
+ return (db.prepare("SELECT 1 FROM models WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
1054
+ db.prepare("SELECT 1 FROM fields WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
1055
+ db.prepare("SELECT 1 FROM rules WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
1056
+ db.prepare("SELECT 1 FROM edges WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined);
1057
+ }
1058
+ /**
1059
+ * r72g(P0,2026-11-17 探针实证):`schema.field` 带点写法的统一解析。
1060
+ *
1061
+ * 探针 49 次调用里关系型快查三问无一问一调,卡点是同一个:`graph impact field
1062
+ * crm_contract.status` 按**原样**查 code → totals 全 0(错误结论「可安全改」),
1063
+ * 裸 status 才有 datarules 4 + listviews 6。references 面 r58 已解析带点写法,
1064
+ * 但 impact/search/MCP explore 三处没跟——同一写法四个入口三个静默假阴性。
1065
+ * 这里收敛为唯一入口:仅 kind=field、输入是单层 `a.b` 形状、且点前段是索引
1066
+ * 已知 schema 时,解析为 `{code, schemaCode}` 做精确过滤查询。
1067
+ *
1068
+ * 未通过校验(点前段不是已知 schema / 多层点 / 含空白)返回 null:调用方**按
1069
+ * 原样**查询,并在零命中时给 dotted 提示——把「前缀拼错」从静默假阴性变成
1070
+ * 一句可行动的纠偏。model/service 不走这里:它们的 code 无 schema 归属,带点
1071
+ * 就是字面 code。
1072
+ */
1073
+ function resolveScopedFieldCode(db, raw) {
1074
+ if (/\s/.test(raw))
1075
+ return null;
1076
+ const split = splitScopedCode(raw);
1077
+ if (split === null)
1078
+ return null;
1079
+ return schemaKnownToIndex(db, split.schemaCode) ? split : null;
1080
+ }
1081
+ /**
1082
+ * MCP/调用方用:对 query 做同样的 `schema.field` 解析(开一次索引校验前段)。
1083
+ * 形状不符直接返回 null,不开库;索引缺席/多份歧义由 resolveGraphDbPath 抛出。
1084
+ */
1085
+ export function parseScopedFieldQuery(query, selector = {}) {
1086
+ if (/\s/.test(query) || splitScopedCode(query) === null)
1087
+ return null;
1088
+ const db = new (nodeSqlite().DatabaseSync)(resolveGraphDbPath(selector.root, selector.env), { readOnly: true });
1089
+ try {
1090
+ return resolveScopedFieldCode(db, query);
1091
+ }
1092
+ finally {
1093
+ db.close();
1094
+ }
1095
+ }
1096
+ /**
1097
+ * r72g:输入含点但未解析成功(点前段不是已知 schema)时的零命中护栏——说明
1098
+ * 为什么按原样查不到,并给两个出口(裸 code + schemaCode 参数 / 换已索引前缀)。
1099
+ */
1100
+ function unresolvedScopedCodeNote(raw) {
1101
+ const dot = raw.indexOf(".");
1102
+ if (dot <= 0)
1103
+ return undefined;
1104
+ const prefix = raw.slice(0, dot);
1105
+ return `;按原样查询未命中——code 含点,若意图是 schema.field 消歧,「${prefix}」不在索引的 schema 清单里,可用裸 code + schemaCode 参数(或换已索引的 schema 前缀重试)`;
1106
+ }
937
1107
  export function queryGraphReferences(kind, rawCode, selector = {}) {
938
1108
  const { db, summary } = openGraphIndex(selector);
939
1109
  try {
940
1110
  // 字段可带宿主模型限定(`crm_contract.contract_no`):只认字段面——
941
1111
  // model/service 的 code 本身含点会歧义,那里保持原样查询。
942
- const scoped = kind === "field" ? splitScopedCode(rawCode) : null;
1112
+ // r72g:解析必须过「点前段是已知 schema」校验——未校验的解析会把拼错的
1113
+ // 前缀变成 schema_code 过滤的静默假阴性(和带点不解析一个病,换个入口)。
1114
+ const scoped = kind === "field" ? resolveScopedFieldCode(db, rawCode) : null;
943
1115
  const code = scoped?.code ?? rawCode;
944
1116
  const rows = (scoped === null
945
1117
  ? db
@@ -983,7 +1155,8 @@ export function queryGraphReferences(kind, rawCode, selector = {}) {
983
1155
  note: (gapped
984
1156
  ? "零命中,但索引存在扫描缺口——不可作为「无引用」证明;先 omc graph pull 重建再查"
985
1157
  : `零命中=仅 scanned 面(规则/数据规则/视图)没有引用它;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有引用;form(表单控件)与 workflow.permissions 未扫描,见 coverage.notScanned——不可据此判定可安全删除`) +
986
- (zeroHitKindHint(db, kind, code, "references") ?? ""),
1158
+ (zeroHitKindHint(db, kind, code, "references") ?? "") +
1159
+ (kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
987
1160
  }
988
1161
  : {}),
989
1162
  ...(gapped
@@ -1072,7 +1245,14 @@ export function readGraphStatus(selector = {}) {
1072
1245
  export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1073
1246
  const { db, summary } = openGraphIndex(selector);
1074
1247
  try {
1075
- const tokens = term.trim().split(/\s+/).filter((token) => token !== "");
1248
+ // r72g(P0):检索词是 `schema.field`(单层、点前段已索引)时,字段面按
1249
+ // 「该 schema + 裸 code/name 子串」精确过滤,规则 FTS 用裸 code——带点写法
1250
+ // 之前在各面都按原样匹配,恒零命中(「关于 crm_contract.amount 有哪些规则」
1251
+ // 查了等于没查)。
1252
+ const trimmed = term.trim();
1253
+ const scoped = resolveScopedFieldCode(db, trimmed);
1254
+ const entityTerm = scoped?.code ?? trimmed;
1255
+ const tokens = entityTerm.split(/\s+/).filter((token) => token !== "");
1076
1256
  let matches = [];
1077
1257
  const entityMatches = {
1078
1258
  model: { count: 0, total: 0, items: [] },
@@ -1113,9 +1293,12 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1113
1293
  ...(offset + rows.length < total ? { truncated: true, nextOffset: offset + rows.length } : {}),
1114
1294
  };
1115
1295
  };
1116
- entityMatches.model = searchEntity("SELECT COUNT(*) AS n FROM models WHERE instr(name, ?) > 0 OR instr(schema_code, ?) > 0", "SELECT schema_code, name, application_code FROM models WHERE instr(name, ?) > 0 OR instr(schema_code, ?) > 0 ORDER BY schema_code LIMIT ?", [term.trim(), term.trim()], (row) => ({ schemaCode: row.schema_code, name: row.name, applicationCode: row.application_code ?? undefined }));
1117
- entityMatches.field = searchEntity("SELECT COUNT(*) AS n FROM fields WHERE instr(name, ?) > 0 OR instr(code, ?) > 0", "SELECT schema_code, code, name, application_code FROM fields WHERE instr(name, ?) > 0 OR instr(code, ?) > 0 ORDER BY schema_code, code LIMIT ?", [term.trim(), term.trim()], (row) => ({ schemaCode: row.schema_code, code: row.code, name: row.name, applicationCode: row.application_code ?? undefined }));
1118
- entityMatches.service = searchEntity("SELECT COUNT(*) AS n FROM services WHERE instr(name, ?) > 0 OR instr(code, ?) > 0", "SELECT code, name FROM services WHERE instr(name, ?) > 0 OR instr(code, ?) > 0 ORDER BY code LIMIT ?", [term.trim(), term.trim()], (row) => ({ code: row.code, name: row.name }));
1296
+ // 字段面:scoped 解析成立时限定宿主模型(精确过滤);模型/服务面保持原样
1297
+ // 检索词——`schema.field` 问的是字段,模型/服务按带点原样查(诚实零命中)。
1298
+ const fieldSchemaPredicate = scoped ? " AND schema_code = ?" : "";
1299
+ entityMatches.model = searchEntity("SELECT COUNT(*) AS n FROM models WHERE instr(name, ?) > 0 OR instr(schema_code, ?) > 0", "SELECT schema_code, name, application_code FROM models WHERE instr(name, ?) > 0 OR instr(schema_code, ?) > 0 ORDER BY schema_code LIMIT ?", [trimmed, trimmed], (row) => ({ schemaCode: row.schema_code, name: row.name, applicationCode: row.application_code ?? undefined }));
1300
+ entityMatches.field = searchEntity(`SELECT COUNT(*) AS n FROM fields WHERE instr(name, ?) > 0 OR instr(code, ?) > 0${fieldSchemaPredicate}`, `SELECT schema_code, code, name, application_code FROM fields WHERE instr(name, ?) > 0 OR instr(code, ?) > 0${fieldSchemaPredicate} ORDER BY schema_code, code LIMIT ?`, [entityTerm, entityTerm, ...(scoped ? [scoped.schemaCode] : [])], (row) => ({ schemaCode: row.schema_code, code: row.code, name: row.name, applicationCode: row.application_code ?? undefined }));
1301
+ entityMatches.service = searchEntity("SELECT COUNT(*) AS n FROM services WHERE instr(name, ?) > 0 OR instr(code, ?) > 0", "SELECT code, name FROM services WHERE instr(name, ?) > 0 OR instr(code, ?) > 0 ORDER BY code LIMIT ?", [trimmed, trimmed], (row) => ({ code: row.code, name: row.name }));
1119
1302
  }
1120
1303
  const gapped = summary.gaps.count > 0;
1121
1304
  return {
@@ -1123,6 +1306,7 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1123
1306
  rules: matches,
1124
1307
  matches: entityMatches,
1125
1308
  index: summary,
1309
+ ...(scoped !== null ? { resolvedScope: { schemaCode: scoped.schemaCode, code: scoped.code } } : {}),
1126
1310
  coverage: { scanned: ["rule.code", "rule.name", "model.code", "model.name", "field.code", "field.name", "service.code", "service.name"], notScanned: ["rule.body", "form", "workflow.permissions"], answerable: ["rule.code", "rule.name", "model.code", "model.name", "field.code", "field.name", "service.code", "service.name"], mustCheckManually: [{ surface: "rule.body", why: "规则体未检索", how: "omc call rule.list --args '{\"schemaCode\":\"<x>\"}'" }, { surface: "form", why: "表单控件未扫描", how: "omc call form.get --args '{\"schemaCode\":\"<x>\"}'" }, { surface: "workflow.permissions", why: "流程权限未扫描", how: "omc call workflow.get --args '{\"schemaCode\":\"<x>\"}'" }], note: "检索覆盖规则与实体的 code/name;规则体、表单与流程权限未扫描" },
1127
1311
  ...(term.trim() !== "" && !/^[A-Za-z][A-Za-z0-9_.-]*$/.test(term.trim()) ? { note: "疑似业务词;本工具同时检索实体 name/code 与规则 code/name,引用明细请使用匹配到的 code 再查 references/impact" } : {}),
1128
1312
  ...(matches.length === 0 && entityMatches.model.total === 0 && entityMatches.field.total === 0 && entityMatches.service.total === 0
@@ -1132,7 +1316,8 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1132
1316
  // 实测摩擦(2026-10-30,zlt测试):中文子串 0 命中后没有下一步提示,
1133
1317
  // 调用方在「换个词再试」里打转。把两个出口都写进 note:CJK 词首
1134
1318
  // 通配 + 找引用走 references/impact。
1135
- : `实体检索:没有命中模型/字段/服务的 name 或 code;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有该实体。\n规则检索:没有命中规则 code/name;规则搜索只匹配词首(例如「增加预算」是一个词,「预算」匹配不到),请给全词、词首或英文 code 前缀。找"谁引用了 X"请走 references/impact <kind> <code>。`,
1319
+ : `实体检索:没有命中模型/字段/服务的 name 或 code;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有该实体。\n规则检索:没有命中规则 code/name;规则搜索只匹配词首(例如「增加预算」是一个词,「预算」匹配不到),请给全词、词首或英文 code 前缀。找"谁引用了 X"请走 references/impact <kind> <code>。` +
1320
+ (scoped === null ? unresolvedScopedCodeNote(trimmed) ?? "" : ""),
1136
1321
  }
1137
1322
  : {}),
1138
1323
  ...(gapped ? { gapWarning: `索引有 ${summary.gaps.count} 个扫描缺口;命中列表可能不完整` } : {}),
@@ -1149,18 +1334,26 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1149
1334
  * read/write these codes — verify those too." Bounded: 50 rules, 20 codes per
1150
1335
  * kind; the same fail-closed gap semantics as references apply.
1151
1336
  */
1152
- export function impactGraph(kind, code, selector = {}) {
1337
+ export function impactGraph(kind, rawCode, selector = {}) {
1153
1338
  const { db, summary } = openGraphIndex(selector);
1154
1339
  try {
1340
+ // r72g(P0,2026-11-17 探针):impact 是带点写法假阴性的重灾区——
1341
+ // `impact field crm_contract.status` 按原样查 code → totals 全 0 →
1342
+ // 「可安全改」的错误结论。与 references 同一解析入口:kind=field 且
1343
+ // `schema.field` 点前段已索引 → 精确过滤;未解析成功按原样查 + 零命中 note。
1344
+ const scoped = kind === "field" ? resolveScopedFieldCode(db, rawCode) : null;
1345
+ const code = scoped?.code ?? rawCode;
1346
+ const schemaPredicate = scoped ? " AND schema_code = ?" : "";
1347
+ const schemaParams = scoped ? [scoped.schemaCode] : [];
1155
1348
  const hop1 = db
1156
- .prepare("SELECT DISTINCT schema_code, rule_code FROM edges WHERE kind = ? AND code = ? AND node_type NOT IN ('datarule', 'listview') ORDER BY schema_code, rule_code LIMIT 51")
1157
- .all(kind, code);
1349
+ .prepare(`SELECT DISTINCT schema_code, rule_code FROM edges WHERE kind = ? AND code = ?${schemaPredicate} AND node_type NOT IN ('datarule', 'listview') ORDER BY schema_code, rule_code LIMIT 51`)
1350
+ .all(kind, code, ...schemaParams);
1158
1351
  const dataruleHits = db
1159
- .prepare("SELECT DISTINCT schema_code, node_code AS targets, via FROM edges WHERE kind = ? AND code = ? AND node_type = 'datarule' ORDER BY schema_code, node_code, via LIMIT 21")
1160
- .all(kind, code);
1352
+ .prepare(`SELECT DISTINCT schema_code, node_code AS targets, via FROM edges WHERE kind = ? AND code = ?${schemaPredicate} AND node_type = 'datarule' ORDER BY schema_code, node_code, via LIMIT 21`)
1353
+ .all(kind, code, ...schemaParams);
1161
1354
  const listViewHits = db
1162
- .prepare("SELECT DISTINCT schema_code, node_code AS view_code, via FROM edges WHERE kind = ? AND code = ? AND node_type = 'listview' ORDER BY schema_code, node_code, via LIMIT 21")
1163
- .all(kind, code);
1355
+ .prepare(`SELECT DISTINCT schema_code, node_code AS view_code, via FROM edges WHERE kind = ? AND code = ?${schemaPredicate} AND node_type = 'listview' ORDER BY schema_code, node_code, via LIMIT 21`)
1356
+ .all(kind, code, ...schemaParams);
1164
1357
  const capped = hop1.length > 50;
1165
1358
  const refsFor = db.prepare("SELECT kind, code, via FROM edges WHERE schema_code = ? AND rule_code = ? AND node_type <> 'datarule' ORDER BY kind, code, via");
1166
1359
  const ruleName = db.prepare("SELECT name FROM rules WHERE schema_code = ? AND rule_code = ?");
@@ -1197,19 +1390,21 @@ export function impactGraph(kind, code, selector = {}) {
1197
1390
  const gapped = summary.gaps.count > 0;
1198
1391
  return {
1199
1392
  kind,
1200
- code,
1393
+ code: rawCode,
1201
1394
  rules,
1202
1395
  datarules: dataruleHits.slice(0, 20).map((hit) => ({ schemaCode: hit.schema_code, targets: hit.targets ?? "", via: hit.via })),
1203
1396
  listviews: listViewHits.slice(0, 20).map((hit) => ({ schemaCode: hit.schema_code, viewCode: hit.view_code ?? "", via: hit.via })),
1204
1397
  totals: { rules: hop1.length, datarules: dataruleHits.length, listviews: listViewHits.length, touchedServices: services.size, touchedModels: models.size, touchedFields: fields.size },
1205
1398
  index: summary,
1206
1399
  coverage: GRAPH_COVERAGE,
1400
+ ...(scoped !== null ? { resolvedScope: { schemaCode: scoped.schemaCode, code: scoped.code } } : {}),
1207
1401
  ...(hop1.length === 0 && dataruleHits.length === 0 && listViewHits.length === 0
1208
1402
  ? {
1209
1403
  note: (gapped
1210
1404
  ? "零命中,但索引存在扫描缺口——不可作为「无影响」证明;先 omc graph pull 重建再查"
1211
1405
  : "零命中=仅 scanned 面(规则/数据规则/视图)没有影响;form(表单控件)与 workflow.permissions 未扫描,见 coverage.notScanned——不可据此判定「删除无影响」") +
1212
- (zeroHitKindHint(db, kind, code, "impact") ?? ""),
1406
+ (zeroHitKindHint(db, kind, code, "impact") ?? "") +
1407
+ (kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
1213
1408
  }
1214
1409
  : {}),
1215
1410
  ...(capped || dataruleHits.length > 20 || listViewHits.length > 20
@@ -159,6 +159,11 @@ export const BUSINESSRULE_LANE_CONTRACT = Object.freeze({
159
159
  }),
160
160
  "rule.references": Object.freeze({
161
161
  scope: "cross-rule reference search",
162
+ // r72g 覆盖面对照(在线仅 businessrule vs 离线三面+条件叶子)不进本
163
+ // description:description 逐字节进 MCP tools/list(bench.test.ts 上限
164
+ // 295,400B,HEAD 4c524b83 实测 295,331 仅余 69B——加对照句即红门)。对照
165
+ // 教学住 read-shapes 的 notes[0](默认 describe 面即回,不进 tools/list);
166
+ // MCP 面的同款对照由 omc_graph_explore 的 description 承担。
162
167
  description: "跨规则引用检索(r23 实证的能力缺失:agent 为查『谁引用了服务 X』枚举了全平台 147 个 schema×ruleCode 组合/171 次 rule.get——本工具一调替代)。kind=service 查 BIZ_ACTION 的 methodMapping.serviceCode;kind=model 查 CREATE/UPDATE/DELETE 的 targetObjectCode 与 methodMapping.schemaCode(删模型前的影响面);kind=field 查 dataActions.targetDataItem 与 inputMappings/outputMappings 的 bizCode(删字段前的影响面;字段 code 跨模型不唯一,建议配 schemaCodes 限范围)。实现为客户端聚合(model.list→rule.list→rule.get 全扫,约几十次 wire 读、几秒完),输出只回命中行。第一版不含:条件叶子里的字段引用、datarule 引用、workflow.bindRule 绑定。",
163
168
  }),
164
169
  "rule.save": Object.freeze({
@@ -319,7 +319,7 @@ export function registerBusinessRuleLane(tools) {
319
319
  (args.schemaCodes !== undefined
320
320
  ? `仅扫描了 schemaCodes 收窄的 ${scoped.length} 个模型(${scoped.slice(0, 5).join(", ")}${scoped.length > 5 ? "…" : ""})——引用常发生在**其他**模型上;要全平台结论请去掉 schemaCodes`
321
321
  : "全平台没有规则引用它") +
322
- "。范围:service→methodMapping.serviceCode;model→targetObjectCode/methodMapping.schemaCode;field→dataActions.targetDataItem/映射 bizCode(不含条件叶子与 datarule,第一版边界)。本工具是在线单点扫描;要离线毫秒级复询、字段级影响面或两跳爆炸半径,先 `omc graph pull --env <env>` 再 `omc graph references|impact <kind> <code>`",
322
+ "。范围:service→methodMapping.serviceCode;model→targetObjectCode/methodMapping.schemaCode;field→dataActions.targetDataItem/映射 bizCode(不含条件叶子与 datarule——条件叶子已入 graph 索引 rule.condition 边,条件引用先 `omc graph pull` 后 `graph references field`)。本工具是在线单点扫描;要离线毫秒级复询、字段级影响面或两跳爆炸半径,先 `omc graph pull --env <env>` 再 `omc graph references|impact <kind> <code>`",
323
323
  ...(scope !== undefined ? { hint: applicationScopeHint(scope, "引用") } : {}),
324
324
  }
325
325
  : {
@@ -340,7 +340,7 @@ export function registerBusinessRuleLane(tools) {
340
340
  description: RULE_TOOLS["rule.get"].description,
341
341
  inputSchema: {
342
342
  environment: environmentArg,
343
- id: z.string().min(1).optional().describe("规则记录 id(历史版本行可能指向旧图);也可改用 schemaCode + ruleCode 业务键定位"),
343
+ id: z.string().min(1).optional().describe("规则记录 id——更新会铸新 ID,旧 id 读到旧图(回执标 staleId/latestId);当前生效行用 schemaCode + ruleCode 定位"),
344
344
  schemaCode: z.string().min(1).optional().describe("业务键定位:模型 code(与 ruleCode 同传,免去先 rule.list 取 id)"),
345
345
  ruleCode: z.string().min(1).optional().describe("业务键定位:规则 code(如 Create/Update/自定义),与 schemaCode 同传"),
346
346
  full: z.boolean().optional().describe("返回原始存储图(含确定性布局 x/y/width/height 与路由 points);默认返回语义图,确定性布局已投影去掉(可直接重存,保存时会重新生成布局)"),
@@ -392,6 +392,10 @@ export function registerBusinessRuleLane(tools) {
392
392
  // Ticket 109 — stale-row detection: same-code saves mint NEW record
393
393
  // ids while old ids stay readable (historical graphs). Reading by a
394
394
  // superseded id shows an OLD graph; flag it and pin the effective id.
395
+ // Online #39 (friction E) sharpens the receipt: the frontend holding
396
+ // the old id renders the old graph and reads as "the change didn't
397
+ // take" — so the flag set also carries the issue-shaped trio
398
+ // (staleId/latestId/note) next to the ticket-109 names.
395
399
  let staleRow = false;
396
400
  let effectiveId;
397
401
  let staleRowMessage;
@@ -409,6 +413,7 @@ export function registerBusinessRuleLane(tools) {
409
413
  // the list face being unreachable must not break the row readback
410
414
  }
411
415
  }
416
+ const staleNote = "该 ID 非当前生效行——rule.save 更新会生成新记录 ID,旧 ID 仍可读旧图;用 latestId 或按 ruleCode 读";
412
417
  const projected = projectRuleGraph(parse(record.node), routes, args.full === true);
413
418
  // 存量体检(2026-10-16 中冶反馈):读回不只给结构,还跑一次写面同源的
414
419
  // dry-lint,把"已启用但运行时会被静默跳过/UI 独有算子/选项 key 撞车"
@@ -463,7 +468,7 @@ export function registerBusinessRuleLane(tools) {
463
468
  schedulerSetting: parse(record.schedulerSetting),
464
469
  renderCompat,
465
470
  ...(semanticFindings ? { semanticFindings } : {}),
466
- ...(staleRow ? { staleRow, effectiveId, staleRowMessage } : {}),
471
+ ...(staleRow ? { staleRow, effectiveId, staleRowMessage, staleId: true, latestId: effectiveId, note: staleNote } : {}),
467
472
  };
468
473
  if (args.withRuntime === true) {
469
474
  const coding = record.developmentMode === 1 || record.developmentMode === "1" || record.developmentMode === "CODING";
@@ -516,6 +521,9 @@ export function registerBusinessRuleLane(tools) {
516
521
  ? payload.schedulerSetting.dataSourceType
517
522
  : undefined,
518
523
  ...(payload.statusLag ? { statusLag: payload.statusLag, statusNote: payload.statusNote } : {}),
524
+ // #39 摩擦 E:summary 面也要带 stale 提示——持旧 id 的调用方常只看
525
+ // summary,漏掉 stale 会把旧图当成「改了没生效」。
526
+ ...(staleRow ? { staleId: true, latestId: effectiveId, note: staleNote } : {}),
519
527
  };
520
528
  }
521
529
  if (args.keys !== undefined) {
@@ -1174,8 +1174,8 @@ async function collectFieldDeleteImpact(session, args, options) {
1174
1174
  },
1175
1175
  ...(unknowns.length > 0 ? { unknown: unknowns } : {}),
1176
1176
  note: options.full
1177
- ? "完整影响面(规则+表单+视图+在线JS+行数)。删除不会自动清理依赖面残留。"
1178
- : "摘要影响面(表单+视图+在线JS+行数;规则请看 dry-run)。删除不会自动清理依赖面残留。",
1177
+ ? "完整影响面(规则+表单+视图+在线JS+行数)。删除不会自动清理依赖面残留。规则条件叶子本在线扫描不含(rule.conditions)——条件引用面已可离线一次查全:omc graph pull --env <env> 后 omc graph references field <schemaCode>.<code>(rule.condition 边)。"
1178
+ : "摘要影响面(表单+视图+在线JS+行数;规则请看 dry-run)。删除不会自动清理依赖面残留。规则条件叶子引用走离线索引(omc graph pull 后 graph references field,rule.condition 边)。",
1179
1179
  };
1180
1180
  }
1181
1181
  /** The proven field.update write body — shared by the write tool and the cascade path. */
@@ -15,12 +15,12 @@ export const FORM_WIRE = Object.freeze({
15
15
  publishAlreadyPublished: "published:true with force!==true skips as already-published",
16
16
  forceRepublish: "onlinejs.compose passes force:true so it can re-promote after a prior publish",
17
17
  emptyLayoutGuard: "ticket 74: the platform designer's Save is NOT lossless — it clears draftViewJson to \"[]\" and draftAttributesJson to \"{}\"; form.draft refuses CALLER-PROVIDED empty layouts (blocker form-empty-layout, zero wire, escape allowEmptyLayout:true) and form.publish refuses to promote a draft with fewer controls than the published face (blocker form-publish-degrade, escape allowDegrade:true); the recovery path is the form version history (/api/api/app/bizsheet/history/list) — fetch the intact version's view/attributes originals and rewrite the draft before publishing",
18
- formButtons: "form toolbar buttons are a three-layer configuration (live 2026-10-23, 1.1.25): (1) bizsheet.options.customButtonJson — a STRINGIFIED JSON array — is the authoring face; ModelManagementFacadeImpl.publishBizForm:1022 turns it into h_biz_button rows with triggerType=FORM, triggerCode=<formCode> at publish; (2) those rows are what ActionPermissionHandler.getByTriggerTypeAndCode(FORM, bizCode) reads; (3) whether a button shows at a node is filtered by the workflow activity's buttonPermission.customBtns[].enabled (the designer 表单操作 checkboxes) plus showPermCode; the execute face is POST /api/api/runtime/form/executeCustomButton {bizButtonModel, bizObjectList:[<full bizObject>], reacquireDataFromDb:true} — NOT the list-button launcher path with ids[]",
18
+ formButtons: "form toolbar buttons are a three-layer configuration (live 2026-10-23, 1.1.25; shape corrected by GitLab #38 live 8.6.26 2026-11-16): (1) bizsheet.options.customButtonJson — a JSON ARRAY with each entry's actionConfig as an OBJECT (the designer's save shape; a STRINGIFIED array is double encoding the platform stores verbatim and the form page then silently drops every button — the pre-r72 CLI form, now unwrapped+healed on every write and linted via shapeWarning in readbacks) — is the authoring face; ModelManagementFacadeImpl.publishBizForm:1022 turns it into h_biz_button rows with triggerType=FORM, triggerCode=<formCode> at publish; (2) those rows are what ActionPermissionHandler.getByTriggerTypeAndCode(FORM, bizCode) reads; (3) whether a button shows at a node is filtered by the workflow activity's buttonPermission.customBtns[].enabled (the designer 表单操作 checkboxes) plus showPermCode; the execute face is POST /api/api/runtime/form/executeCustomButton {bizButtonModel, bizObjectList:[<full bizObject>], reacquireDataFromDb:true} — NOT the list-button launcher path with ids[]",
19
19
  actionsColumns: "ticket 100: draftActionsJson/publishedActionsJson are REAL bizsheet columns (BizForm.java:95-100 @SerializableField; BizFormModel.java:59-62 serialized by bizsheet/get) — the designer writes draftActionsJson on save and both faces on publish (frontend-dist/admin/js/4280.cfa75764.js offsets 193538/185347); form.get full:true surfaces them; publish promotes draftActionsJson → publishedActionsJson",
20
20
  });
21
- 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`(表单工具栏按钮)。传 `controls:["code",…]` 只取指定控件的 options(如关联控件的 mappings);传 `full:true` 才返回 draft/published 的完整 view/attributes/html/actions JSON(actions 列为设计器保存/发布的表单级按钮动作)。体积大,仅在需要整体布局时用。';
22
- 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`;**要到 form.publish 才生成 h_biz_button(triggerType=FORM)**,且表单页是否显示还取决于流程节点 `buttonPermission.customBtns[].enabled`(设计器「表单操作」勾选)。`useLocation` 用 FORM/ROW/LIST,表单工具栏按钮用 FORM。 **表单控件属性(含关联填充 mappings)从字段行派生**:改关联映射的事实源在字段 options.mappings(field.update → field.publish),直接改这里的控件映射会被平台按字段重算覆盖(真机 2026-10-14 实证);字段发布后如需刷新已发布表单的控件映射,用本工具 rebuild:false 重存(保留现有布局与在线JS)再 form.publish。";
23
- 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` 必须是**字符串化数组**(对象会 50000 syntax error);表单页是否显示再由流程节点 `buttonPermission.customBtns[].enabled` 过滤。";
21
+ 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 列为设计器保存/发布的表单级按钮动作)。体积大,仅在需要整体布局时用。';
22
+ 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。 **表单控件属性(含关联填充 mappings)从字段行派生**:改关联映射的事实源在字段 options.mappings(field.update → field.publish),直接改这里的控件映射会被平台按字段重算覆盖(真机 2026-10-14 实证);字段发布后如需刷新已发布表单的控件映射,用本工具 rebuild:false 重存(保留现有布局与在线JS)再 form.publish。";
23
+ 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` 过滤。";
24
24
  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`(launcher/domain_service_runtime/<schema>/<rule> + ids[])**——同一绑定规则在 rule.run 面已验证可用(r28b 实证),不要在 executeCustomButton 上反复重试。";
25
25
  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).";
26
26
  export const FORM_LANE_CONTRACT = Object.freeze({
@@ -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, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender } from "../form-support.js";
4
+ import { executeFormDraftWrite, executeFormPublishWrite, executeFormRunButtonWrite, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender, customButtonJsonStoredShape, CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } 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";
@@ -158,7 +158,14 @@ export function registerFormLane(tools) {
158
158
  // used to drop `options`, so a read→write round trip could never
159
159
  // carry the buttons back.
160
160
  options: sheet.options ?? null,
161
+ // #39 (GitLab, live 8.6.26): the authoritative button read. This
162
+ // projection used to decode ONLY the legacy stringified form, so a
163
+ // designer-authored ARRAY came back null while the store held real
164
+ // buttons — the read face was blind to them. readFormButtons now
165
+ // decodes both; a dirty stringified column is parsed AND flagged
166
+ // instead of silently echoed as "configured".
161
167
  customButtonJson: readFormButtons(sheet.options),
168
+ ...(customButtonJsonStoredShape(sheet.options) === "string" ? { customButtonJsonShapeWarning: CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } : {}),
162
169
  // Ticket 109 — render compatibility: the Online JS panel resolves
163
170
  // generateCodeType(e) whose first line is `if(!e||!e.tagName)
164
171
  // return ""` and then does o[type].push(...) (54286.fbbb415f.js)
@@ -304,7 +311,7 @@ export function registerFormLane(tools) {
304
311
  buttons: z
305
312
  .array(z.record(z.unknown()))
306
313
  .optional()
307
- .describe("表单工具栏按钮(写进 biz_sheet.options.customButtonJson;publish 时才生成 h_biz_button(triggerType=FORM))。每条至少 code/name/bindAction/operateType,useLocation 默认 FORM"),
314
+ .describe("表单工具栏按钮(写进 biz_sheet.options.customButtonJson;publish 时才生成 h_biz_button(triggerType=FORM))。每条至少 code/name/bindAction/operateType,useLocation 默认 FORM;新建还需 triggerCode/triggerType/showPermCode/showPermType + name_i18n(JSON 串形)+ addviewType,缺则平台 40000(#38 实证);code 语义化"),
308
315
  customButtonJson: z.string().optional().describe("buttons 的原样 JSON 数组字符串(与 buttons 互斥;用于把 form.get 读回值直接回写)"),
309
316
  buttonsMode: z.enum(["merge", "replace"]).optional().describe("默认 merge:按 code 增量 upsert(改一个按钮不必重发全表);replace:整表替换"),
310
317
  removeButtonCodes: z.array(z.string().min(1)).optional().describe("要删除的按钮 code(仅 merge 模式)"),
@@ -1355,6 +1355,21 @@ export function validateMethodMapping(mapping, nodeCode) {
1355
1355
  if (typeof m[key] !== "string" || !m[key].trim())
1356
1356
  blockers.push({ code: "rule-graph-bizaction-mapping-key", nodeCode, key: `methodMapping.${key}`, message: `methodMapping.${key} 必须是非空字符串(8.6.26 BizMethodMappingModel;serviceCode+serviceMethodCode 是存在性校验对)` });
1357
1357
  }
1358
+ // 线上 #38(摩擦 B,詹记 8.6.26 真机):创建链 methodMapping 缺 serviceName/
1359
+ // serviceMethodName/methodCode 时平台按非空列落库失败,rule.save 回 40000
1360
+ // 「调用数据库发生异常」(照最小示例形状必炸;对照已成功规则补齐三键后一次
1361
+ // 成功)。只 warning 不拒——平台版本可能有差异,存量读回图也可能天然缺这三键
1362
+ // (透传语义不动),提示补齐而不是阻断。
1363
+ const nameSlotKeys = ["serviceName", "serviceMethodName", "methodCode"];
1364
+ const missingNameSlotKeys = nameSlotKeys.filter((key) => typeof m[key] !== "string" || !m[key].trim());
1365
+ if (missingNameSlotKeys.length > 0)
1366
+ blockers.push({
1367
+ code: "rule-graph-bizaction-mapping-names-missing",
1368
+ nodeCode,
1369
+ key: `methodMapping.${missingNameSlotKeys.join("/")}`,
1370
+ severity: "warning",
1371
+ message: `methodMapping 缺 ${missingNameSlotKeys.join("/")}——8.6.26 创建链按非空列落库,缺这些键时平台回 40000「调用数据库发生异常」(线上 #38 实证:补齐后一次成功)。对照 rule.get 读回的成功规则补齐;平台版本可能有差异,故仅提示不拦截`,
1372
+ });
1358
1373
  const mappingArrays = [["inputMappings", m.inputMappings], ["outputMappings", m.outputMappings]];
1359
1374
  for (const [listKey, list] of mappingArrays) {
1360
1375
  if (list === undefined)