@stalfh233/omc-cli 0.6.66 → 0.6.68
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/call.js +12 -1
- package/dist/cli-contract.js +11 -0
- package/dist/cli.js +64 -5
- package/dist/goal-routes.js +22 -5
- package/dist/graph.js +231 -28
- package/dist/lanes/businessrule-contract.js +5 -0
- package/dist/lanes/businessrule.js +148 -30
- package/dist/lanes/field.js +33 -2
- package/dist/lanes/list-view-contract.js +2 -2
- package/dist/lanes/list-view.js +72 -10
- package/dist/lanes/rule-graph.js +2 -2
- package/dist/lanes/runtime-data.js +8 -3
- package/dist/mcp-graph.js +56 -27
- package/dist/read-shapes.js +14 -0
- package/dist/rule-support.js +118 -79
- package/dist/tool-types.js +11 -0
- package/dist/write.js +6 -0
- package/package.json +3 -3
- package/skills/omc-start-here.md +1 -1
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
|
|
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
|
-
|
|
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
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* the
|
|
240
|
-
*
|
|
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
|
-
|
|
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) {
|
|
@@ -262,8 +334,16 @@ export function extractReferenceEdges(schemaCode, ruleCode, nodes) {
|
|
|
262
334
|
if (["CREATE", "UPDATE", "DELETE"].includes(String(node.nodeType ?? ""))) {
|
|
263
335
|
push("model", String(node.targetObjectCode ?? ""), node, "targetObjectCode");
|
|
264
336
|
if (Array.isArray(node.dataActions))
|
|
265
|
-
for (const action of node.dataActions)
|
|
337
|
+
for (const action of node.dataActions) {
|
|
266
338
|
push("field", String(action.targetDataItem ?? ""), node, "dataActions.targetDataItem");
|
|
339
|
+
// r73(r72g 报告遗留的相邻盲区):DYNAMIC 赋值的来源字段
|
|
340
|
+
// (currentDataItemValue)与 EXPRESSION value 里的 `{字段}` 模板同样是
|
|
341
|
+
// 配置里的字段引用——只入承载模型侧(来源就是本行字段),不改变既有
|
|
342
|
+
// targetDataItem 的归属语义。
|
|
343
|
+
push("field", String(action.currentDataItemValue ?? ""), node, "dataActions.currentDataItemValue");
|
|
344
|
+
for (const token of conditionValueTokens(action.value))
|
|
345
|
+
push("field", token, node, "dataActions.value-token");
|
|
346
|
+
}
|
|
267
347
|
}
|
|
268
348
|
if (mapping) {
|
|
269
349
|
push("model", String(mapping.schemaCode ?? ""), node, "methodMapping.schemaCode");
|
|
@@ -274,6 +354,40 @@ export function extractReferenceEdges(schemaCode, ruleCode, nodes) {
|
|
|
274
354
|
push("field", String(row.bizCode), node, label);
|
|
275
355
|
}
|
|
276
356
|
}
|
|
357
|
+
// r72g: condition leaves on this node (deduped per node — a leaf repeating
|
|
358
|
+
// `id` on both sides of an identity filter is one edge per side-model).
|
|
359
|
+
const nodeType = String(node.nodeType ?? "");
|
|
360
|
+
const nodeCode = String(node.nodeCode ?? "");
|
|
361
|
+
const queriedSchema = String(node.targetSchemaCode ?? "").split(".")[0] ?? "";
|
|
362
|
+
const actingModel = queriedSchema || ((nodeType === "UPDATE" || nodeType === "DELETE") ? String(node.targetObjectCode ?? "") : "") || schemaCode;
|
|
363
|
+
const seen = new Set();
|
|
364
|
+
for (const key of RULE_CONDITION_NODE_CONTAINERS) {
|
|
365
|
+
if (node[key] === undefined || node[key] === null)
|
|
366
|
+
continue;
|
|
367
|
+
walkConditionLeaves(node[key], leafVisitor(actingModel, nodeCode, seen));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Routes: evidenced condition homes are all node-level, but a stored route
|
|
371
|
+
// carrying a condition container must not silently vanish — walk it too.
|
|
372
|
+
for (const route of routes) {
|
|
373
|
+
const routeCode = `${String(route.preNode ?? "")}->${String(route.postNode ?? "")}`;
|
|
374
|
+
walkConditionLeaves(route, leafVisitor(schemaCode, routeCode, new Set()));
|
|
375
|
+
}
|
|
376
|
+
// Scheduler rules (bizRuleType=2): the scan filter lives rule-level in
|
|
377
|
+
// schedulerSetting.filterConditionGroups, not on any node. GET_LIST scans the
|
|
378
|
+
// hosting model, so both leaf sides attribute to it.
|
|
379
|
+
let scheduler = schedulerSetting;
|
|
380
|
+
if (typeof scheduler === "string") {
|
|
381
|
+
try {
|
|
382
|
+
scheduler = JSON.parse(scheduler);
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
scheduler = undefined;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (scheduler && typeof scheduler === "object" && !Array.isArray(scheduler)) {
|
|
389
|
+
const settings = scheduler;
|
|
390
|
+
walkConditionLeaves(settings.filterConditionGroups, leafVisitor(schemaCode, "SCHEDULER", new Set()));
|
|
277
391
|
}
|
|
278
392
|
return edges;
|
|
279
393
|
}
|
|
@@ -510,6 +624,8 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
510
624
|
gaps.push({ kind: "rule-graph-parse", ref: `${schemaCode}/${ruleCode}` });
|
|
511
625
|
return;
|
|
512
626
|
}
|
|
627
|
+
const routes = decodeJsonColumn(record.route, JSON_COLUMN_NULL_COALESCE);
|
|
628
|
+
const schedulerSetting = decodeJsonColumn(record.schedulerSetting, JSON_COLUMN_NULL_COALESCE);
|
|
513
629
|
rules.push({
|
|
514
630
|
schemaCode,
|
|
515
631
|
ruleCode,
|
|
@@ -518,9 +634,10 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
518
634
|
status: typeof record.status === "string" ? record.status : null,
|
|
519
635
|
defaultRule: typeof record.defaultRule === "boolean" ? record.defaultRule : null,
|
|
520
636
|
rowId: ruleId,
|
|
521
|
-
graphSha256: sha256({ nodes, routes
|
|
637
|
+
graphSha256: sha256({ nodes, routes }),
|
|
522
638
|
});
|
|
523
|
-
|
|
639
|
+
// r72g:条件叶子(node 容器 + route 兜底 + 定时规则 schedulerSetting)一并入边。
|
|
640
|
+
edges.push(...extractReferenceEdges(schemaCode, ruleCode, nodes, Array.isArray(routes) ? routes : [], schedulerSetting).map((edge) => ({ ...edge, applicationCode })));
|
|
524
641
|
}
|
|
525
642
|
catch (error) {
|
|
526
643
|
gaps.push({ kind: "rule-get", ref: `${schemaCode}/${ruleCode}`, note: error instanceof Error ? error.message : String(error) });
|
|
@@ -886,17 +1003,22 @@ function openGraphIndex(selector = {}) {
|
|
|
886
1003
|
* 分散定义就会被漏掉一处(MCP 面第一版就漏了)。
|
|
887
1004
|
*/
|
|
888
1005
|
export const GRAPH_COVERAGE = Object.freeze({
|
|
1006
|
+
// r72g(2026-11-17):businessrule 面从「结构引用」扩到「条件叶子」——规则
|
|
1007
|
+
// nodeGraph 各条件容器(filterCondition/targetConditionGroups/
|
|
1008
|
+
// exitConditionGroups/dataCondition/…)+ 定时规则 schedulerSetting.
|
|
1009
|
+
// filterConditionGroups 的字段引用以 rule.condition 边入索引;schema 升到
|
|
1010
|
+
// 8 强制旧库重拉,避免旧索引在新声明下静默漏答。
|
|
889
1011
|
scanned: Object.freeze(["businessrule", "datarule", "listview"]),
|
|
890
|
-
notScanned: Object.freeze(["form", "workflow.permissions", "workflow.bindings", "onlinejs"
|
|
1012
|
+
notScanned: Object.freeze(["form", "workflow.permissions", "workflow.bindings", "onlinejs"]),
|
|
891
1013
|
answerable: Object.freeze(["businessrule", "datarule", "listview"]),
|
|
892
1014
|
mustCheckManually: Object.freeze([
|
|
893
1015
|
{ surface: "form", why: "表单控件关联未扫描,可能仍引用目标字段", how: "omc call form.get --args '{\"schemaCode\":\"<x>\"}'" },
|
|
894
1016
|
{ surface: "workflow.permissions", why: "流程权限未扫描,无法判断谁能发起/操作", how: "omc call workflow.get --args '{\"schemaCode\":\"<x>\"}'" },
|
|
895
1017
|
{ surface: "workflow.bindings", why: "流程规则绑定未扫描,规则删除可能留下绑定", how: "omc call workflow.get --args '{\"schemaCode\":\"<x>\"}'" },
|
|
896
1018
|
{ 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
1019
|
]),
|
|
899
1020
|
note: "零命中/全零 totals 只代表 scanned 面没有命中;notScanned 面(尤其 form 与 workflow.permissions)未扫描,不可据此判定可安全删除或无影响",
|
|
1021
|
+
crossFace: "在线对照面:`omc call rule.references`(实时,仅 businessrule,不含条件叶子);本索引(离线快照,businessrule+datarule+listview,且含规则条件叶子 rule.condition 边)——条件里的字段引用离线一次可答,在线面要 rule.get 逐条看",
|
|
900
1022
|
});
|
|
901
1023
|
/**
|
|
902
1024
|
* Zero-hit disambiguation (2026-10-31 capability-test friction, hit twice in
|
|
@@ -934,12 +1056,70 @@ function splitScopedCode(code) {
|
|
|
934
1056
|
return null; // 只认一层 a.b
|
|
935
1057
|
return { schemaCode, code: bare };
|
|
936
1058
|
}
|
|
1059
|
+
/** r72g:点前段是否是索引里的已知 schema(models 实体表优先,fields/rules/edges 兜底)。 */
|
|
1060
|
+
function schemaKnownToIndex(db, schemaCode) {
|
|
1061
|
+
return (db.prepare("SELECT 1 FROM models WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
|
|
1062
|
+
db.prepare("SELECT 1 FROM fields WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
|
|
1063
|
+
db.prepare("SELECT 1 FROM rules WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined ||
|
|
1064
|
+
db.prepare("SELECT 1 FROM edges WHERE schema_code = ? LIMIT 1").get(schemaCode) !== undefined);
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* r72g(P0,2026-11-17 探针实证):`schema.field` 带点写法的统一解析。
|
|
1068
|
+
*
|
|
1069
|
+
* 探针 49 次调用里关系型快查三问无一问一调,卡点是同一个:`graph impact field
|
|
1070
|
+
* crm_contract.status` 按**原样**查 code → totals 全 0(错误结论「可安全改」),
|
|
1071
|
+
* 裸 status 才有 datarules 4 + listviews 6。references 面 r58 已解析带点写法,
|
|
1072
|
+
* 但 impact/search/MCP explore 三处没跟——同一写法四个入口三个静默假阴性。
|
|
1073
|
+
* 这里收敛为唯一入口:仅 kind=field、输入是单层 `a.b` 形状、且点前段是索引
|
|
1074
|
+
* 已知 schema 时,解析为 `{code, schemaCode}` 做精确过滤查询。
|
|
1075
|
+
*
|
|
1076
|
+
* 未通过校验(点前段不是已知 schema / 多层点 / 含空白)返回 null:调用方**按
|
|
1077
|
+
* 原样**查询,并在零命中时给 dotted 提示——把「前缀拼错」从静默假阴性变成
|
|
1078
|
+
* 一句可行动的纠偏。model/service 不走这里:它们的 code 无 schema 归属,带点
|
|
1079
|
+
* 就是字面 code。
|
|
1080
|
+
*/
|
|
1081
|
+
function resolveScopedFieldCode(db, raw) {
|
|
1082
|
+
if (/\s/.test(raw))
|
|
1083
|
+
return null;
|
|
1084
|
+
const split = splitScopedCode(raw);
|
|
1085
|
+
if (split === null)
|
|
1086
|
+
return null;
|
|
1087
|
+
return schemaKnownToIndex(db, split.schemaCode) ? split : null;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* MCP/调用方用:对 query 做同样的 `schema.field` 解析(开一次索引校验前段)。
|
|
1091
|
+
* 形状不符直接返回 null,不开库;索引缺席/多份歧义由 resolveGraphDbPath 抛出。
|
|
1092
|
+
*/
|
|
1093
|
+
export function parseScopedFieldQuery(query, selector = {}) {
|
|
1094
|
+
if (/\s/.test(query) || splitScopedCode(query) === null)
|
|
1095
|
+
return null;
|
|
1096
|
+
const db = new (nodeSqlite().DatabaseSync)(resolveGraphDbPath(selector.root, selector.env), { readOnly: true });
|
|
1097
|
+
try {
|
|
1098
|
+
return resolveScopedFieldCode(db, query);
|
|
1099
|
+
}
|
|
1100
|
+
finally {
|
|
1101
|
+
db.close();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* r72g:输入含点但未解析成功(点前段不是已知 schema)时的零命中护栏——说明
|
|
1106
|
+
* 为什么按原样查不到,并给两个出口(裸 code + schemaCode 参数 / 换已索引前缀)。
|
|
1107
|
+
*/
|
|
1108
|
+
function unresolvedScopedCodeNote(raw) {
|
|
1109
|
+
const dot = raw.indexOf(".");
|
|
1110
|
+
if (dot <= 0)
|
|
1111
|
+
return undefined;
|
|
1112
|
+
const prefix = raw.slice(0, dot);
|
|
1113
|
+
return `;按原样查询未命中——code 含点,若意图是 schema.field 消歧,「${prefix}」不在索引的 schema 清单里,可用裸 code + schemaCode 参数(或换已索引的 schema 前缀重试)`;
|
|
1114
|
+
}
|
|
937
1115
|
export function queryGraphReferences(kind, rawCode, selector = {}) {
|
|
938
1116
|
const { db, summary } = openGraphIndex(selector);
|
|
939
1117
|
try {
|
|
940
1118
|
// 字段可带宿主模型限定(`crm_contract.contract_no`):只认字段面——
|
|
941
1119
|
// model/service 的 code 本身含点会歧义,那里保持原样查询。
|
|
942
|
-
|
|
1120
|
+
// r72g:解析必须过「点前段是已知 schema」校验——未校验的解析会把拼错的
|
|
1121
|
+
// 前缀变成 schema_code 过滤的静默假阴性(和带点不解析一个病,换个入口)。
|
|
1122
|
+
const scoped = kind === "field" ? resolveScopedFieldCode(db, rawCode) : null;
|
|
943
1123
|
const code = scoped?.code ?? rawCode;
|
|
944
1124
|
const rows = (scoped === null
|
|
945
1125
|
? db
|
|
@@ -983,7 +1163,8 @@ export function queryGraphReferences(kind, rawCode, selector = {}) {
|
|
|
983
1163
|
note: (gapped
|
|
984
1164
|
? "零命中,但索引存在扫描缺口——不可作为「无引用」证明;先 omc graph pull 重建再查"
|
|
985
1165
|
: `零命中=仅 scanned 面(规则/数据规则/视图)没有引用它;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有引用;form(表单控件)与 workflow.permissions 未扫描,见 coverage.notScanned——不可据此判定可安全删除`) +
|
|
986
|
-
(zeroHitKindHint(db, kind, code, "references") ?? "")
|
|
1166
|
+
(zeroHitKindHint(db, kind, code, "references") ?? "") +
|
|
1167
|
+
(kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
|
|
987
1168
|
}
|
|
988
1169
|
: {}),
|
|
989
1170
|
...(gapped
|
|
@@ -1072,7 +1253,14 @@ export function readGraphStatus(selector = {}) {
|
|
|
1072
1253
|
export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
|
|
1073
1254
|
const { db, summary } = openGraphIndex(selector);
|
|
1074
1255
|
try {
|
|
1075
|
-
|
|
1256
|
+
// r72g(P0):检索词是 `schema.field`(单层、点前段已索引)时,字段面按
|
|
1257
|
+
// 「该 schema + 裸 code/name 子串」精确过滤,规则 FTS 用裸 code——带点写法
|
|
1258
|
+
// 之前在各面都按原样匹配,恒零命中(「关于 crm_contract.amount 有哪些规则」
|
|
1259
|
+
// 查了等于没查)。
|
|
1260
|
+
const trimmed = term.trim();
|
|
1261
|
+
const scoped = resolveScopedFieldCode(db, trimmed);
|
|
1262
|
+
const entityTerm = scoped?.code ?? trimmed;
|
|
1263
|
+
const tokens = entityTerm.split(/\s+/).filter((token) => token !== "");
|
|
1076
1264
|
let matches = [];
|
|
1077
1265
|
const entityMatches = {
|
|
1078
1266
|
model: { count: 0, total: 0, items: [] },
|
|
@@ -1113,9 +1301,12 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
|
|
|
1113
1301
|
...(offset + rows.length < total ? { truncated: true, nextOffset: offset + rows.length } : {}),
|
|
1114
1302
|
};
|
|
1115
1303
|
};
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1304
|
+
// 字段面:scoped 解析成立时限定宿主模型(精确过滤);模型/服务面保持原样
|
|
1305
|
+
// 检索词——`schema.field` 问的是字段,模型/服务按带点原样查(诚实零命中)。
|
|
1306
|
+
const fieldSchemaPredicate = scoped ? " AND schema_code = ?" : "";
|
|
1307
|
+
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 }));
|
|
1308
|
+
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 }));
|
|
1309
|
+
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
1310
|
}
|
|
1120
1311
|
const gapped = summary.gaps.count > 0;
|
|
1121
1312
|
return {
|
|
@@ -1123,6 +1314,7 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
|
|
|
1123
1314
|
rules: matches,
|
|
1124
1315
|
matches: entityMatches,
|
|
1125
1316
|
index: summary,
|
|
1317
|
+
...(scoped !== null ? { resolvedScope: { schemaCode: scoped.schemaCode, code: scoped.code } } : {}),
|
|
1126
1318
|
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
1319
|
...(term.trim() !== "" && !/^[A-Za-z][A-Za-z0-9_.-]*$/.test(term.trim()) ? { note: "疑似业务词;本工具同时检索实体 name/code 与规则 code/name,引用明细请使用匹配到的 code 再查 references/impact" } : {}),
|
|
1128
1320
|
...(matches.length === 0 && entityMatches.model.total === 0 && entityMatches.field.total === 0 && entityMatches.service.total === 0
|
|
@@ -1132,7 +1324,8 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
|
|
|
1132
1324
|
// 实测摩擦(2026-10-30,zlt测试):中文子串 0 命中后没有下一步提示,
|
|
1133
1325
|
// 调用方在「换个词再试」里打转。把两个出口都写进 note:CJK 词首
|
|
1134
1326
|
// 通配 + 找引用走 references/impact。
|
|
1135
|
-
: `实体检索:没有命中模型/字段/服务的 name 或 code;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有该实体。\n规则检索:没有命中规则 code/name;规则搜索只匹配词首(例如「增加预算」是一个词,「预算」匹配不到),请给全词、词首或英文 code 前缀。找"谁引用了 X"请走 references/impact <kind> <code
|
|
1327
|
+
: `实体检索:没有命中模型/字段/服务的 name 或 code;本索引覆盖应用:${summary.coverage.applicationCodes.join("、") || "(未知)"},不代表其他应用没有该实体。\n规则检索:没有命中规则 code/name;规则搜索只匹配词首(例如「增加预算」是一个词,「预算」匹配不到),请给全词、词首或英文 code 前缀。找"谁引用了 X"请走 references/impact <kind> <code>。` +
|
|
1328
|
+
(scoped === null ? unresolvedScopedCodeNote(trimmed) ?? "" : ""),
|
|
1136
1329
|
}
|
|
1137
1330
|
: {}),
|
|
1138
1331
|
...(gapped ? { gapWarning: `索引有 ${summary.gaps.count} 个扫描缺口;命中列表可能不完整` } : {}),
|
|
@@ -1149,18 +1342,26 @@ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
|
|
|
1149
1342
|
* read/write these codes — verify those too." Bounded: 50 rules, 20 codes per
|
|
1150
1343
|
* kind; the same fail-closed gap semantics as references apply.
|
|
1151
1344
|
*/
|
|
1152
|
-
export function impactGraph(kind,
|
|
1345
|
+
export function impactGraph(kind, rawCode, selector = {}) {
|
|
1153
1346
|
const { db, summary } = openGraphIndex(selector);
|
|
1154
1347
|
try {
|
|
1348
|
+
// r72g(P0,2026-11-17 探针):impact 是带点写法假阴性的重灾区——
|
|
1349
|
+
// `impact field crm_contract.status` 按原样查 code → totals 全 0 →
|
|
1350
|
+
// 「可安全改」的错误结论。与 references 同一解析入口:kind=field 且
|
|
1351
|
+
// `schema.field` 点前段已索引 → 精确过滤;未解析成功按原样查 + 零命中 note。
|
|
1352
|
+
const scoped = kind === "field" ? resolveScopedFieldCode(db, rawCode) : null;
|
|
1353
|
+
const code = scoped?.code ?? rawCode;
|
|
1354
|
+
const schemaPredicate = scoped ? " AND schema_code = ?" : "";
|
|
1355
|
+
const schemaParams = scoped ? [scoped.schemaCode] : [];
|
|
1155
1356
|
const hop1 = db
|
|
1156
|
-
.prepare(
|
|
1157
|
-
.all(kind, code);
|
|
1357
|
+
.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`)
|
|
1358
|
+
.all(kind, code, ...schemaParams);
|
|
1158
1359
|
const dataruleHits = db
|
|
1159
|
-
.prepare(
|
|
1160
|
-
.all(kind, code);
|
|
1360
|
+
.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`)
|
|
1361
|
+
.all(kind, code, ...schemaParams);
|
|
1161
1362
|
const listViewHits = db
|
|
1162
|
-
.prepare(
|
|
1163
|
-
.all(kind, code);
|
|
1363
|
+
.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`)
|
|
1364
|
+
.all(kind, code, ...schemaParams);
|
|
1164
1365
|
const capped = hop1.length > 50;
|
|
1165
1366
|
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
1367
|
const ruleName = db.prepare("SELECT name FROM rules WHERE schema_code = ? AND rule_code = ?");
|
|
@@ -1197,19 +1398,21 @@ export function impactGraph(kind, code, selector = {}) {
|
|
|
1197
1398
|
const gapped = summary.gaps.count > 0;
|
|
1198
1399
|
return {
|
|
1199
1400
|
kind,
|
|
1200
|
-
code,
|
|
1401
|
+
code: rawCode,
|
|
1201
1402
|
rules,
|
|
1202
1403
|
datarules: dataruleHits.slice(0, 20).map((hit) => ({ schemaCode: hit.schema_code, targets: hit.targets ?? "", via: hit.via })),
|
|
1203
1404
|
listviews: listViewHits.slice(0, 20).map((hit) => ({ schemaCode: hit.schema_code, viewCode: hit.view_code ?? "", via: hit.via })),
|
|
1204
1405
|
totals: { rules: hop1.length, datarules: dataruleHits.length, listviews: listViewHits.length, touchedServices: services.size, touchedModels: models.size, touchedFields: fields.size },
|
|
1205
1406
|
index: summary,
|
|
1206
1407
|
coverage: GRAPH_COVERAGE,
|
|
1408
|
+
...(scoped !== null ? { resolvedScope: { schemaCode: scoped.schemaCode, code: scoped.code } } : {}),
|
|
1207
1409
|
...(hop1.length === 0 && dataruleHits.length === 0 && listViewHits.length === 0
|
|
1208
1410
|
? {
|
|
1209
1411
|
note: (gapped
|
|
1210
1412
|
? "零命中,但索引存在扫描缺口——不可作为「无影响」证明;先 omc graph pull 重建再查"
|
|
1211
1413
|
: "零命中=仅 scanned 面(规则/数据规则/视图)没有影响;form(表单控件)与 workflow.permissions 未扫描,见 coverage.notScanned——不可据此判定「删除无影响」") +
|
|
1212
|
-
(zeroHitKindHint(db, kind, code, "impact") ?? "")
|
|
1414
|
+
(zeroHitKindHint(db, kind, code, "impact") ?? "") +
|
|
1415
|
+
(kind === "field" && scoped === null ? unresolvedScopedCodeNote(rawCode) ?? "" : ""),
|
|
1213
1416
|
}
|
|
1214
1417
|
: {}),
|
|
1215
1418
|
...(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({
|