@stalfh233/omc-cli 0.6.66 → 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.
@@ -734,14 +734,29 @@ function readOverviewRoute(registry, goal, index) {
734
734
  * `field.list`(读字段定义)——答的不是「谁引用了它」。r57 探针从零搭 6 个工作包,
735
735
  * `omc graph` **一次都没用过**,尽管 `omc help omc-start-here` §1b 写得很详细。
736
736
  *
737
- * 保守触发:只在**明确问引用/影响/删除前检查**时给,且不改变原有 route——
738
- * 只追加一条可核对的指路,原有路由行照旧。给不出唯一目标 code 时只给
737
+ * r72g(2026-11-17 探针)扩了两处:
738
+ * ① 触发面——盘点型关系问句(「关于 X 配了哪些规则」「哪些字段被规则用到」)
739
+ * 不带「引用/使用/影响」词面,r57 词表接不住,但答案同样一次索引查询可答;
740
+ * ② 定位——note 首句从「是本地引用索引」升级为「关系型问题第一入口」
741
+ * (探针实测:否定结论靠 9 次 rule.get 枚举拿到,索引 1 次可答)。
742
+ *
743
+ * 保守触发:只在**明确问引用/影响/删除前检查/规则盘点**时给,且不改变原有
744
+ * route——只追加一条可核对的指路,原有路由行照旧。给不出唯一目标 code 时只给
739
745
  * `status`/`search` 这类**不带 code 也能跑**的入口。
740
746
  */
741
747
  const GRAPH_INTENT_RE = /(?:谁|哪(?:个|些|里))?(?:引用|使用|用到|依赖|被用|用到了)|影响面|影响范围|爆炸半径|牵连|波及|删(?:除|掉)?(?:前|之前|了会不会|会怎样|有没有风险)|能不能删|可以删(?:吗|么)|\bimpact\b|\breferences?\b|\bwho uses\b/i;
748
+ /**
749
+ * 盘点型关系问句(r72g):只认「问规则/关联清单」的固定形状,不认裸「规则」
750
+ * (那会把规则写问句也劫来)。聚合词在场时让位——数值聚合不是关系查询,
751
+ * goalRouteInner 的聚合专项(data.list + --jq 自行计数)才是正解;词表镜像自
752
+ * 那里的 AGGREGATE_ASK(函数内常量),改词请两处同步。
753
+ */
754
+ const GRAPH_INVENTORY_RE = /有哪些规则|配了(?:哪些|什么)规则|关于.{1,12}的规则|被.{0,8}(?:规则|条件|视图)用到|跟.{1,10}(?:有关联|相关)/;
755
+ const GRAPH_AGGREGATE_RE = /(统计|分组|汇总|聚合|计数|条数(?!据)|多少条|有几条|数一下)/;
742
756
  const GRAPH_OBJECT_RE = /\b([a-z][a-z0-9]*(?:_[a-z0-9]+)+)\b/g;
743
757
  function graphHintFor(goal) {
744
- if (!GRAPH_INTENT_RE.test(goal))
758
+ // 引用/影响词面照旧;盘点型问句要过聚合闸(「统计配了哪些规则」是计数不是关系)。
759
+ if (!GRAPH_INTENT_RE.test(goal) && !(GRAPH_INVENTORY_RE.test(goal) && !GRAPH_AGGREGATE_RE.test(goal)))
745
760
  return undefined;
746
761
  const codes = [...new Set(goal.match(GRAPH_OBJECT_RE) ?? [])];
747
762
  // ⚠️ 参数面不同(2026-11-12 真机逐条验证):`status`/`references` 收 --env(仅作绑定提示),
@@ -749,7 +764,9 @@ function graphHintFor(goal) {
749
764
  // 给用户一份跑不通的命令比不给更糟,所以这里按子命令分别拼。
750
765
  const commands = codes.length === 1
751
766
  ? [
752
- `omc graph references field ${codes[0]} --env <环境名>`,
767
+ // r72g:字段 code 跨模型不唯一(rule.references 同一边界)——schema.field
768
+ // r72g 核心已落地 schema.field 解析(2026-11-17)——措辞从「将支持」改「支持」。
769
+ `omc graph references field ${codes[0]} --env <环境名> # 字段重名时消歧用 schema.field 写法(<schema>.${codes[0]})`,
753
770
  `omc graph references model ${codes[0]} --env <环境名>`,
754
771
  `omc graph impact model ${codes[0]} # 注意:impact 不收 --env`,
755
772
  ]
@@ -762,7 +779,7 @@ function graphHintFor(goal) {
762
779
  state: "unknown",
763
780
  firstCommand: "omc graph status --env <环境名>; 无索引则 omc graph pull --env <环境名>(只读,约 1 分钟)",
764
781
  commands,
765
- note: "图谱是本地的引用索引(毫秒级):一次调用答「谁引用了它」,替代逐模型 model.inspect / rule.get 枚举。索引不含规则条件叶子与流程绑定,命中后仍以 rule.get 原文为准。宿主接了 MCP 时用 omc_graph_explore(安装器自动注册)。",
782
+ note: "关系型问题第一入口:一次毫秒级答「谁用到 X / 关于 X 配了哪些规则 / 改动影响」,替代逐模型 rule.list/rule.get 枚举(r72g 探针实测 9 次 rule.get 才拿到的否定结论,索引 1 次可答)。索引含规则条件叶子(rule.condition 边),不含流程绑定,命中后仍以 rule.get 原文为准。宿主接了 MCP 时用 omc_graph_explore(安装器自动注册)。",
766
783
  };
767
784
  }
768
785
  function goalRouteInner(registry, goal) {
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
  : {
@@ -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. */
package/dist/mcp-graph.js CHANGED
@@ -3,7 +3,7 @@ import { DatabaseSync } from "node:sqlite";
3
3
  import { readdirSync } from "node:fs";
4
4
  import { basename, join, resolve, sep } from "node:path";
5
5
  import { createInterface } from "node:readline";
6
- import { GraphIndexError, graphRoot, impactGraph, listGraphIndexes, queryGraphReferences, readGraphStatus, resolveGraphDbPath, searchGraphRules, } from "./graph.js";
6
+ import { GRAPH_COVERAGE, GraphIndexError, graphRoot, impactGraph, listGraphIndexes, parseScopedFieldQuery, queryGraphReferences, readGraphStatus, resolveGraphDbPath, searchGraphRules, } from "./graph.js";
7
7
  /**
8
8
  * Stdio MCP server for the local rule-graph index (ADR-0008).
9
9
  *
@@ -116,12 +116,20 @@ function respond(id, result) {
116
116
  function respondError(id, code, message) {
117
117
  process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id: id ?? null, error: { code, message } })}\n`);
118
118
  }
119
- const INSTRUCTIONS_INDEXED = [
120
- "规则/配置图检索(本地索引,先于逐平台扫描使用):",
121
- "- 改名/删除/重构一个 字段(field)/模型(model)/服务(service) 前,先用 omc_graph_explore 查引用与影响面;查\"谁引用了 X\"也走它。",
119
+ /**
120
+ * r72g(2026-11-17 探针)重排:第一句从「改名/删除前必查」改为**关系型快查定位**——
121
+ * 探针 49 次调用里「哪些字段被规则用到/改 status 注意什么/关于 amount 有哪些规则」
122
+ * 三问无一问一调,都是逐模型 model.inspect/rule.list 枚举出来的。索引本来就是
123
+ * 这些问题的第一入口,instructions 却只教了破坏性变更前置检查一个触发场景。
124
+ * (导出供测试钉住定位语,防止将来又被改窄。)
125
+ */
126
+ export const INSTRUCTIONS_INDEXED = [
127
+ "规则/配置图检索——回答关系型配置问题的第一入口(本地索引,先于逐平台扫描):谁用到 X / 关于 X 配了哪些规则 / 改动 X 影响什么,毫秒级一次答全,替代逐模型 model.inspect/rule.list 枚举(N 次调用 → 1 次)。",
128
+ "- 改名/删除/重构一个 字段(field)/模型(model)/服务(service) 前,必先用 omc_graph_explore 查引用与影响面;查\"谁引用了 X\"也走它。",
129
+ "- 覆盖对照(先验):在线面 `omc call rule.references`(实时,仅 businessrule,不含条件叶子);本索引(离线快照,businessrule+datarule+listview,且含规则条件叶子 rule.condition 边)——条件里的字段引用离线一次可答,在线面要 rule.get 逐条看。",
122
130
  "- 不确定查哪个库时先调 omc_graph_projects(零参数):列出所有项目根 + 各自可查的环境名。",
123
131
  "- 每个索引的身份是「项目根 + 环境名」这一对:同一个项目可以同时建了 test/prod 等多份,同一环境也可以被多个项目各自 pull。所以 explore/status 用 project(目录名或绝对路径)+ env 指定;只给 env 时不唯一就会报歧义并列出可用环境。",
124
- "- 索引只覆盖:业务规则(methodMapping/targetObjectCode)、数据规则(propertyCodes 与公式 {字段})、视图(列/排序/条件)。**不含**规则条件叶子与流程绑定。",
132
+ "- query 可为业务名(实体 name+code 子串)、字段/模型/服务 code,或 `<schemaCode>.<字段code>`(同名字段精确消歧,如 crm_contract.contract_no)。",
125
133
  "- search 语义:只匹配规则 code+name 的**词首**(中文子串不命中:搜「预算」匹配不到「增加预算」)。",
126
134
  "答案带 environmentName/projectPath/dbId 与 freshness/pulledAtIso——索引是快照(平台侧改动后需 CLI 重建:omc graph pull --path <项目根> --env <env>,只读远端约 1 分钟),且多库并存时靠这三个字段自证归属。",
127
135
  ].join("\n");
@@ -133,17 +141,17 @@ const INSTRUCTIONS_NO_INDEX = [
133
141
  const EXPLORE_TOOL = {
134
142
  name: "omc_graph_explore",
135
143
  description: [
136
- "一次查全一个目标的引用与影响面(本地索引,毫秒级)。",
137
- "输入 query 可为业务名(实体 name+code 子串)或规则 code+name 词首;也可直接给字段/模型/服务 code。kind 可选 field|model|service,不给则三种都查。",
144
+ "回答关系型配置问题的第一入口——\"谁用到 X?\"\"关于 X 配了哪些规则?\"\"改动 X 影响什么?\":一次查全引用与影响面(本地索引,毫秒级),替代逐模型 model.inspect/rule.list 枚举。",
145
+ "输入 query 可为业务名(实体 name+code 子串)、规则 code+name 词首、字段/模型/服务 code,或 `<schemaCode>.<字段code>`(同名字段精确消歧,如 crm_contract.contract_no)。kind 可选 field|model|service,不给则三种都查。",
138
146
  "返回 {index(freshness), references:{kind:[{schemaCode,ruleCode,nodeCode,nodeType,via,referrer,isSelf}]}, impact:{kind:totals}, search:{matches:{model,field,service},rules}}。",
139
- "references/impact 支持 offset+limit 分页;truncated 时按返回的 nextOffset 继续调用。实体分页结果带 nextCall;分页不会改变 resolved。字段同名时请用 schemaCode 消歧。",
147
+ "references/impact 支持 offset+limit 分页;truncated 时按返回的 nextOffset 继续调用。实体分页结果带 nextCall;分页不会改变 resolved。字段同名时用 schemaCode 参数或 <schemaCode>.<字段code> 写法消歧。",
148
+ "覆盖对照(先验):在线面 `omc call rule.references` 实时但仅 businessrule、不含条件叶子;本索引是离线快照(businessrule 含条件叶子 rule.condition 边 + datarule + listview)——条件里的字段引用离线一次可答;freshness=partial 时命中可能不完整(答案里有 gapWarning)。",
140
149
  "改/删/重命名任何字段、模型、服务之前必查;找\"关于 X 的规则\"拿 code 也走这里。",
141
- "索引不含规则条件叶子与流程绑定;freshness=partial 时命中可能不完整(答案里有 gapWarning)。",
142
150
  ].join(" "),
143
151
  inputSchema: {
144
152
  type: "object",
145
153
  properties: {
146
- query: { type: "string", description: "业务名(实体 name+code 子串)、字段/模型/服务 code,或规则检索词(规则 code+name 词首匹配)" },
154
+ query: { type: "string", description: "业务名(实体 name+code 子串)、字段/模型/服务 code、`<schemaCode>.<字段code>`(同名字段精确消歧),或规则检索词(规则 code+name 词首匹配)" },
147
155
  queries: { type: "array", items: { type: "string" }, description: "实体面多条件检索;与 query 并存时合并,match 默认 any" },
148
156
  match: { type: "string", enum: ["all", "any"], description: "queries[] 的模型∪字段所属模型求交/并" },
149
157
  kind: { type: "string", enum: [...KINDS], description: "限定一种引用种类;省略则 field/model/service 全查" },
@@ -309,6 +317,13 @@ export async function executeGraphTool(name, rawArgs, context) {
309
317
  const selector = selectorOf(args);
310
318
  const status = readGraphStatus(selector);
311
319
  const index = status.index;
320
+ // r72g(P0):query 支持 `<schemaCode>.<字段code>` 带点写法——探针被旧
321
+ // description 的「用 schemaCode 消歧」引导出带点写法,撞上 impact/search/
322
+ // 实体解析三处静默假阴性。这里解析一次供实体归位(resolved 回显、候选与
323
+ // schema 过滤);引用/影响面由 graph.ts 内部同一解析兜底。
324
+ const scopedQuery = parseScopedFieldQuery(primaryQuery, selector);
325
+ const effectiveSchemaCode = schemaCode ?? scopedQuery?.schemaCode;
326
+ const effectiveQuery = scopedQuery?.code ?? query;
312
327
  const kinds = kind === undefined ? [...KINDS] : [kind];
313
328
  const offset = typeof args.offset === "number" && Number.isSafeInteger(args.offset) && args.offset >= 0 ? args.offset : 0;
314
329
  const limit = typeof args.limit === "number" && Number.isSafeInteger(args.limit) && args.limit > 0 && args.limit <= MATCH_CAP ? args.limit : MATCH_CAP;
@@ -326,13 +341,19 @@ export async function executeGraphTool(name, rawArgs, context) {
326
341
  },
327
342
  } : search;
328
343
  const resolvedSearch = searchGraphRules(primaryQuery, MATCH_CAP, 0, selector);
329
- const loweredQuery = primaryQuery.toLocaleLowerCase();
344
+ const loweredQuery = effectiveQuery.toLocaleLowerCase();
330
345
  const allCandidates = entityInventory(selector).filter((r) => (r.code.toLocaleLowerCase().includes(loweredQuery) || r.name.toLocaleLowerCase().includes(loweredQuery)) &&
331
- (!schemaCode || (r.kind !== "service" && r.schemaCode === schemaCode)) &&
332
- (!applicationCode || r.applicationCode === applicationCode));
333
- const candidatesForQuery = (term) => entityInventory(selector).filter((r) => (r.code.toLocaleLowerCase().includes(term.toLocaleLowerCase()) || r.name.toLocaleLowerCase().includes(term.toLocaleLowerCase())) &&
334
- (!schemaCode || (r.kind !== "service" && r.schemaCode === schemaCode)) &&
346
+ (!effectiveSchemaCode || (r.kind !== "service" && r.schemaCode === effectiveSchemaCode)) &&
335
347
  (!applicationCode || r.applicationCode === applicationCode));
348
+ const candidatesForQuery = (term) => {
349
+ // r72g:queries[] 里的带点词同样按 schema.field 解析后再匹配。
350
+ const scopedTerm = parseScopedFieldQuery(term, selector);
351
+ const needle = (scopedTerm?.code ?? term).toLocaleLowerCase();
352
+ return entityInventory(selector).filter((r) => (r.code.toLocaleLowerCase().includes(needle) || r.name.toLocaleLowerCase().includes(needle)) &&
353
+ (!scopedTerm || (r.kind !== "service" && r.schemaCode === scopedTerm.schemaCode)) &&
354
+ (!effectiveSchemaCode || (r.kind !== "service" && r.schemaCode === effectiveSchemaCode)) &&
355
+ (!applicationCode || r.applicationCode === applicationCode));
356
+ };
336
357
  const perQueryModels = queries.map((term) => new Set(candidatesForQuery(term).filter((r) => r.kind === "model").map((r) => r.schemaCode)));
337
358
  const perQueryFieldModels = queries.map((term) => new Set(candidatesForQuery(term).filter((r) => r.kind === "field").map((r) => r.schemaCode)));
338
359
  const combine = (sets) => {
@@ -346,17 +367,21 @@ export async function executeGraphTool(name, rawArgs, context) {
346
367
  const hitFieldModels = combine(perQueryFieldModels);
347
368
  const typedCandidates = kind ? allCandidates.filter((r) => r.kind === kind) : allCandidates;
348
369
  const fieldCandidates = kind === "field" ? typedCandidates : allCandidates.filter((r) => r.kind === "field");
349
- const exactSame = fieldCandidates.filter((r) => r.code === query);
350
- const ambiguous = kind === "field" && !schemaCode && exactSame.length > 1;
370
+ const exactSame = fieldCandidates.filter((r) => r.code === effectiveQuery);
371
+ const ambiguous = kind === "field" && !effectiveSchemaCode && exactSame.length > 1;
351
372
  const resolvedEntity = ambiguous ? undefined : typedCandidates[0] ?? (kind === undefined ? allCandidates[0] : undefined);
352
- const subjectByName = query !== (resolvedEntity?.code ?? "") && resolvedEntity;
373
+ const subjectByName = effectiveQuery !== (resolvedEntity?.code ?? "") && resolvedEntity;
353
374
  const subjects = resolvedEntity
354
375
  ? [{ kind: resolvedEntity.kind, code: resolvedEntity.kind === "model" ? (resolvedEntity.schemaCode ?? resolvedEntity.code) : resolvedEntity.code }]
355
376
  : [];
356
377
  for (const one of kinds) {
357
378
  const subject = subjects.find((s) => s.kind === one);
358
- const ref = queryGraphReferences(one, subject?.code ?? query, selector);
359
- const scopedMatches = ref.matches.filter((row) => !applicationCode || row.applicationCode === applicationCode).filter((row) => subject && one === "field" && schemaCode ? row.schemaCode === schemaCode : true);
379
+ // r72g:字段面把 schema 限定(显式 schemaCode 参数或 query 的 schema.field
380
+ // 解析)下推为精确查询——references/impact 在 graph.ts 内统一解析,事后
381
+ // 过滤只救得了 rules 面,datarules/listviews 的 totals 也会随之精确。
382
+ const targetCode = subject && one === "field" && effectiveSchemaCode ? `${effectiveSchemaCode}.${subject.code}` : subject?.code ?? query;
383
+ const ref = queryGraphReferences(one, targetCode, selector);
384
+ const scopedMatches = ref.matches.filter((row) => !applicationCode || row.applicationCode === applicationCode).filter((row) => one === "field" && effectiveSchemaCode ? row.schemaCode === effectiveSchemaCode : true);
360
385
  const capped = cap(scopedMatches, offset, limit);
361
386
  // r35a-F4c(真机 2026-11-06):**MCP 面是第三个消费者**——CLI 的 references
362
387
  // 与 impact 都带 coverage 了,这里若不显式透传,MCP 用户看到的仍是
@@ -367,11 +392,13 @@ export async function executeGraphTool(name, rawArgs, context) {
367
392
  offset: capped.offset,
368
393
  limit: capped.limit,
369
394
  ...(capped.truncated ? { truncated: true, nextOffset: capped.nextOffset, note: `共 ${capped.total} 条,已给 ${capped.rows.length} 条,offset=${capped.offset} 取下一段(调用时传 offset=${capped.nextOffset}、limit=${capped.limit})` } : {}),
395
+ // r72g:`schema.field` 解析生效时回显 resolvedScope,让「精确过滤中」可见。
396
+ ...(ref.resolvedScope !== undefined ? { resolvedScope: ref.resolvedScope } : {}),
370
397
  ...(ref.gapWarning ? { gapWarning: ref.gapWarning } : {}),
371
398
  };
372
399
  if (scopedMatches.length > 0 || kind !== undefined || subject !== undefined) {
373
- const imp = impactGraph(one, subject?.code ?? query, selector);
374
- const scopedRules = subject && one === "field" && schemaCode ? imp.rules.filter((row) => row.schemaCode === schemaCode) : imp.rules;
400
+ const imp = impactGraph(one, targetCode, selector);
401
+ const scopedRules = one === "field" && effectiveSchemaCode ? imp.rules.filter((row) => row.schemaCode === effectiveSchemaCode) : imp.rules;
375
402
  impact[one] = {
376
403
  totals: scopedRules.length === imp.rules.length ? imp.totals : { ...imp.totals, rules: scopedRules.length },
377
404
  rules: cap(scopedRules, offset, limit),
@@ -389,7 +416,7 @@ export async function executeGraphTool(name, rawArgs, context) {
389
416
  };
390
417
  }
391
418
  }
392
- const decorate = (row) => withMatchedOn({ ...row, ...(row.schemaCode && row.code === undefined ? { code: row.schemaCode } : {}) }, query);
419
+ const decorate = (row) => withMatchedOn({ ...row, ...(row.schemaCode && row.code === undefined ? { code: row.schemaCode } : {}) }, effectiveQuery);
393
420
  const decoratedMatches = { ...scopedSearch.matches, model: { ...scopedSearch.matches.model, items: scopedSearch.matches.model.items.map(decorate) }, field: { ...scopedSearch.matches.field, items: scopedSearch.matches.field.items.map(decorate) }, service: { ...scopedSearch.matches.service, items: scopedSearch.matches.service.items.map(decorate) } };
394
421
  const noEntityHit = search.matches.model.total === 0 && search.matches.field.total === 0 && search.matches.service.total === 0;
395
422
  const composite = /\s|\+|,|\b(?:AND|OR)\b/i.test(query);
@@ -404,7 +431,7 @@ export async function executeGraphTool(name, rawArgs, context) {
404
431
  hitModels: [...hitModels],
405
432
  ...(() => { const page = cap([...hitFieldModels].flatMap((schema) => entityInventory(selector).filter((r) => r.kind === "field" && r.schemaCode === schema && (!applicationCode || r.applicationCode === applicationCode)).map((r) => ({ schemaCode: schema, code: r.code, name: r.name }))), offset, limit); return { hitFields: page.rows, hitFieldsCount: page.total, ...(page.truncated ? { hitFieldsTruncated: true, hitFieldsNextOffset: page.nextOffset } : {}) }; })(),
406
433
  found: resolvedEntity !== undefined,
407
- ...(resolvedEntity ? { resolved: { kind: resolvedEntity.kind, schemaCode: "schemaCode" in resolvedEntity ? resolvedEntity.schemaCode : "", code: resolvedEntity.code, matchedOn: { on: resolvedEntity.name.includes(query) ? "name" : "code", fragment: query }, ...(resolvedEntity.applicationCode ? { applicationCode: resolvedEntity.applicationCode } : {}) } } : {}),
434
+ ...(resolvedEntity ? { resolved: { kind: resolvedEntity.kind, schemaCode: "schemaCode" in resolvedEntity ? resolvedEntity.schemaCode : "", code: resolvedEntity.code, matchedOn: { on: resolvedEntity.name.includes(effectiveQuery) ? "name" : "code", fragment: effectiveQuery }, ...(resolvedEntity.applicationCode ? { applicationCode: resolvedEntity.applicationCode } : {}) } } : {}),
408
435
  ...(resolvedEntity ? { otherCandidates: allCandidates.filter((r) => r.code !== resolvedEntity.code).slice(0, 5).map((r) => ({ schemaCode: r.schemaCode ?? r.code, name: r.name, ...(r.applicationCode ? { applicationCode: r.applicationCode } : {}) })) } : {}),
409
436
  ...(ambiguous ? { ambiguous: true, candidates: exactSame.map((r) => ({ schemaCode: r.schemaCode, code: r.code, name: r.name })) } : {}),
410
437
  ...(kind !== undefined ? { kind } : {}),
@@ -418,9 +445,11 @@ export async function executeGraphTool(name, rawArgs, context) {
418
445
  ...(noEntityHit ? { suggestions: suggestions(query, selector), hint: "可尝试 suggestions 中的实体 code/name;引用明细请使用匹配 code 查 references/impact" } : {}),
419
446
  searchNote: `${searchNote}${paginationNote}${queries.length > 1 ? " 规则面(词首匹配)不参与 queries[] 的实体求交。" : ""}`,
420
447
  ...(search.note ? { searchNote: `${searchNote}\n${search.note}` } : {}),
421
- // 旧句「索引不含规则条件叶子与流程绑定」漏了表单与流程权限(r35a-F4 实证
422
- // 探针据此差点误删被表单引用的字段)。改为指向结构化 coverage,不再靠散文。
423
- coverage: { ...index.coverage, scanned: ["businessrule", "datarule", "listview"], notScanned: ["form", "workflow.permissions", "workflow.bindings", "onlinejs", "rule.conditions"] },
448
+ // r72g:不再手抄 scanned/notScanned 清单——三个消费面(CLI references /
449
+ // CLI impact / MCP explore)必须共用 graph.ts 的同一份 GRAPH_COVERAGE 声明,
450
+ // 手抄版已经漂过一次(mustCheckManually/note/crossFace 全丢)。这里直接
451
+ // 展开,新增字段自动透传。
452
+ coverage: { ...index.coverage, ...GRAPH_COVERAGE },
424
453
  note: `零命中只代表 references[].coverage.scanned 面没有命中;字段面覆盖应用:${index.coverage.fields?.coveredApplications.join("、") || "(未知)"};notScanned 面(尤其 form 与 workflow.permissions)未扫描,不可据此判定可安全删除或无影响`,
425
454
  });
426
455
  }
@@ -122,6 +122,17 @@ const READ_SHAPES = {
122
122
  "modelPresent:false 时未发 list(避免幻影 schema 补建 7 条预置)",
123
123
  ],
124
124
  },
125
+ // r72g(2026-11-17 探针):`rule.references`(在线,仅 businessrule)与
126
+ // `omc graph references`(离线,businessrule+datarule+listview 三面)同名不同
127
+ // 覆盖——探针只能读回执 coverage 才发现选错了面。对照进 notes[0]:
128
+ // returnsFace 只显首条,默认 describe 面就要能先验选对面,不是打完才知道。
129
+ "rule.references": {
130
+ keys: ["kind", "code", "scanned:{models,rules,parseFailures?}", "matches:array<{schemaCode,ruleCode,nodeCode,nodeType,via,targetObjectCode?}>", "coverage:{scanned,notScanned,note}", "applicationResolution?", "note?(零命中)", "hint?"],
131
+ notes: [
132
+ "覆盖面对照:本工具=在线实时、仅 businessrule;omc graph references=离线快照、businessrule+datarule+listview 三面(毫秒级,需先 omc graph pull),且已含规则条件叶子(rule.condition 边;本在线面不含,条件引用走 graph);字段消歧 graph 面支持 schema.field 写法",
133
+ "matches:[] 只代表已扫面零命中(coverage.notScanned 是权威,勿当可安全删除);字段 code 跨模型不唯一,建议配 schemaCodes 限范围",
134
+ ],
135
+ },
125
136
  "datarule.list": {
126
137
  keys: ["rules:array<{id,propertyCode,dataRuleType,checkType,optionsKeys?}>", "rulesCount", "modelPresent", "rulesOmitted?"],
127
138
  notes: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.6.66",
3
+ "version": "0.6.67",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "commander": "14.0.3",
59
- "omc-core": "0.6.66",
59
+ "omc-core": "0.6.67",
60
60
  "proper-lockfile": "4.1.2",
61
61
  "write-file-atomic": "6.0.0",
62
62
  "zod": "^3.23.8",
@@ -74,6 +74,6 @@
74
74
  "directory": "packages/omc-cli"
75
75
  },
76
76
  "optionalDependencies": {
77
- "@stalfh233/omc-fake-platform": "0.6.66"
77
+ "@stalfh233/omc-fake-platform": "0.6.67"
78
78
  }
79
79
  }
@@ -27,7 +27,7 @@ be treated as a second source. Read this, then follow the topics it names.
27
27
  - `scout`(能不能/怎么写/是否支持)→ 先探边界(`omc-capability-scouting`),别直接写。若 `next` 返回 **`boundary`**(`match.kind:"boundary"`,如 `ocr-e-signature`/`release-prod`/`inline-coding`),说明需求**不在覆盖内**(`write:false`):如实报告、用 `omc capabilities` 核对,**不要**用相近能力伪造实现。
28
28
  阶梯步骤已内联工具必填参数(`route.ladder[].tools`/`readTools`)与命中 recipe 的 `describe <tool> --example <id>`;据此直接执行——**不要再逐能力扫**(能力族工具面用 `commands --capability <id>`),也不要先扫 `commands --json`/全部 `contract`/全部 `describe --full`。
29
29
  方法论按 `route.readSections` 逐节读:对每条 `{topic, section}` 执行 `omc help <topic> --section "<section>"`(单节 0.4–3.4KB)。`omc help <topic>` 默认只回节索引(约 1KB,含每节字节数);**不要 `--all` 读整篇**(5–14KB,读一次就留在后续每一轮窗口)。**带着具体问题(错误码/跨能力语义/某个词)直接 `omc help --search "<词>"`**——跨全部 topic 全文检索,命中节的正文随结果内联返回,一次调用就是答案;**严禁自己写 `for t in …; do omc help $t --all | grep …` 循环**(r18 实测 12 调用/176KB,检索一次 8KB 搞定)。
30
- 1b. **改/删/重命名既有对象前先看影响面**:`omc graph pull --env <env>` 建本地索引(增量、带锁与 gap 报告;`--all-applications` 或 `--application-codes a,b` 定覆盖),之后 `graph references <kind> <code>` 离线答「谁引用了它」(一调替代逐模型 `rule.get` 枚举),`impact` 看爆炸半径、`search` 找规则 code、`status` 看新鲜度与覆盖、`indexes` 清点多项目×环境。索引身份=「项目根+环境名」对:references/edges/impact/search/status 与 pull 对称认 `--path`/`--env`;多库不给 `--env` 会拒(`graph indexes` 清点);回执带 projectPath/environmentName/dbId 自证归属。索引不含规则条件叶子与流程绑定,命中后以 `rule.get` 原文为准。MCP:`omc mcp-graph --path <根>[,<另一根>]`,用 `project`+`env` 选库(`omc_graph_projects`)。
30
+ 1b. **改/删/重命名既有对象前先看影响面**:`omc graph pull --env <env>` 建本地索引(增量、带锁与 gap 报告;`--all-applications` 或 `--application-codes a,b` 定覆盖),之后 `graph references <kind> <code>` 离线答「谁引用了它」(一调替代逐模型 `rule.get` 枚举),`impact` 看爆炸半径、`search` 找规则 code、`status` 看新鲜度与覆盖、`indexes` 清点多项目×环境。索引身份=「项目根+环境名」对:references/edges/impact/search/status 与 pull 对称认 `--path`/`--env`;多库不给 `--env` 会拒(`graph indexes` 清点);回执带 projectPath/environmentName/dbId 自证归属。索引含规则条件叶子(rule.condition 边),不含流程绑定,命中后以 `rule.get` 原文为准。MCP:`omc mcp-graph --path <根>[,<另一根>]`,用 `project`+`env` 选库(`omc_graph_projects`)。
31
31
 
32
32
  1c. **写后端 Java 源码(在线开发)走工作区而不是一条条 call**:`omc programming pull --env <env> --app <appCode>` 把业务规则源码拉进 `.omc-programming/`(git 可管),改文件后 `omc programming status` → `omc programming apply [--publish]`(逐文件走编程面治理);图形化规则转编码用 `omc programming adopt --schema <s> --rule <r>`;验证用 `omc programming test --schema <s> --rule <r>`(fixture 驱动:compile→publish→触发→断言→清理)。**平台运行时只执行已发布版**:只 save 不 publish 等于没改;publish 内部会编译并把规则切 CODING+enable。包路径/类名不得改。
33
33
  2. 写前只需读 `omc-config-draft-review`(人审门)与 `omc-five-piece-flow`(发现→草稿→权限→执行→回读);`omc-business-configuration` 按命中的能力分节读(见 `next` 的 `readSections`),不要整篇预取。