@stalfh233/omc-cli 0.6.47 → 0.6.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/capability-overview.js +114 -1
  2. package/dist/cli-stdout.js +3 -0
  3. package/dist/cli.js +318 -62
  4. package/dist/closest-match.js +22 -3
  5. package/dist/command-transport.js +5 -1
  6. package/dist/discovery.js +193 -75
  7. package/dist/goal-plan.js +1296 -0
  8. package/dist/goal-routes.js +87 -5
  9. package/dist/graph.js +223 -34
  10. package/dist/intent/capabilities/field.js +24 -0
  11. package/dist/intent/plan-apply.js +10 -3
  12. package/dist/intent/schema.js +24 -1
  13. package/dist/lanes/app.js +4 -0
  14. package/dist/lanes/apply-changes.js +1 -0
  15. package/dist/lanes/b2-registration.js +24 -0
  16. package/dist/lanes/businessrule.js +14 -0
  17. package/dist/lanes/custom-page.js +8 -0
  18. package/dist/lanes/datarule.js +4 -0
  19. package/dist/lanes/dictionary.js +13 -0
  20. package/dist/lanes/environment.js +2 -0
  21. package/dist/lanes/field.js +5 -0
  22. package/dist/lanes/folder.js +4 -0
  23. package/dist/lanes/form.js +5 -0
  24. package/dist/lanes/list-view-contract.js +1 -1
  25. package/dist/lanes/list-view.js +5 -0
  26. package/dist/lanes/meta.js +5 -0
  27. package/dist/lanes/model.js +9 -0
  28. package/dist/lanes/online-js.js +2 -0
  29. package/dist/lanes/organization.js +20 -0
  30. package/dist/lanes/perm.js +5 -5
  31. package/dist/lanes/programming.js +6 -0
  32. package/dist/lanes/report.js +9 -0
  33. package/dist/lanes/rule-lifecycle.js +6 -0
  34. package/dist/lanes/rulelog.js +1 -0
  35. package/dist/lanes/runtime-data.js +39 -1
  36. package/dist/lanes/workflow.js +18 -0
  37. package/dist/mcp-graph.js +180 -41
  38. package/dist/package-tool.js +1 -0
  39. package/dist/recipes/workflow.js +1 -1
  40. package/dist/search-index.js +137 -0
  41. package/dist/tool-search.js +647 -0
  42. package/dist/tool-types.js +6 -0
  43. package/dist/tools.js +1 -0
  44. package/dist/write.js +2 -1
  45. package/docs/omc-introduction.md +5 -7
  46. package/package.json +6 -5
  47. package/skills/omc-business-configuration.md +2 -1
  48. package/skills/omc-capabilities.md +4 -2
  49. package/skills/omc-start-here.md +21 -7
  50. package/skills/omc-tool-selection.md +7 -15
  51. package/skills/omc-write-hazards.md +1 -1
@@ -12,7 +12,7 @@ import { listSkills, readSkillSection } from "./skills.js";
12
12
  */
13
13
  const SCOUT_CUES = ["能不能", "能不能够", "能否", "是否支持", "支持吗", "支持不支持", "可不可以", "有没有办法", "有没有可能", "怎么实现", "如何实现", "怎么写", "怎么配置"];
14
14
  const MODIFY_CUES = ["修改", "调整", "更新", "重命名", "改名", "编辑", "删除", "去掉", "移除", "改为", "改成"];
15
- const READ_CUES = ["查看", "读回", "盘点", "现状", "列出", "有哪些", "有没有", "检查", "审计", "导出", "只读", "看看", "看下", "查一下", "查询一下", "查一查", "梳理", "清点", "给我一份", "哪些", "是什么", "是否", "是否正确", "现有", "已有"];
15
+ const READ_CUES = ["查看", "读回", "盘点", "现状", "列出", "有哪些", "有没有", "检查", "审计", "导出", "只读", "看看", "看下", "查一下", "查询一下", "查一查", "梳理", "清点", "给我一份", "哪些", "是什么", "是否", "是否正确", "现有", "已有", "条数", "多少条", "数一下"];
16
16
  const BUILD_CUES = ["新建", "创建", "搭建", "从零", "从无到有", "做", "建", "加", "实现", "生成", "新增", "保存", "启用", "录入", "添加", "造", "填报", "打卡", "录"];
17
17
  /** Whole-application asks — a single-model atom is the wrong shape for these. */
18
18
  const WHOLE_APP_CUES = ["应用", "系统", "整套", "从零", "从无到有", "端到端", "一条龙", "一整套", "业务应用", "平台"];
@@ -66,6 +66,24 @@ function capabilityWhy(capabilityId, goal) {
66
66
  return capabilityId;
67
67
  }
68
68
  }
69
+ /**
70
+ * Leading read verbs. `READ_CUES` is an "includes anywhere" list, so a bare
71
+ * 「查」 cannot join it without matching 排查/检查/追查… in write asks. But a goal
72
+ * that OPENS with a read verb is unambiguous: 「查采购申请里金额大于一万的单据」
73
+ * is a query even though 「查询一下」/「查一下」 are the only cue phrases.
74
+ *
75
+ * Missing this made a READ ask fall to the default build ladder and match the
76
+ * `workflow.update` recipe (amount thresholds share vocabulary with 金额分级) —
77
+ * a read question handed a write tool. (r59 M6, T2 end-to-end.)
78
+ */
79
+ const LEADING_READ_VERBS = ["查", "看", "读", "列", "搜", "找", "盘", "导出"];
80
+ /** Leading verbs that are ALSO common write verbs when the goal names a target field. */
81
+ const AMBIGUOUS_LEADING_READ = ["统计", "汇总"];
82
+ /**
83
+ * A verb that puts the result SOMEWHERE. 「统计子表异常行数**写入**主表字段」 opens
84
+ * with 统计 but is a compute/写 ask; 「统计这个月提交了多少单据」 is a query.
85
+ */
86
+ const WRITE_DESTINATION = /(写入|写到|写进|回写|落到|存到|更新到|同步到|填到)/;
69
87
  function detectMode(goal) {
70
88
  if (SCOUT_CUES.some((cue) => goal.includes(cue)))
71
89
  return "scout";
@@ -77,6 +95,11 @@ function detectMode(goal) {
77
95
  return "build";
78
96
  if (READ_CUES.some((cue) => goal.includes(cue)))
79
97
  return "read";
98
+ const lead = goal.trimStart();
99
+ if (LEADING_READ_VERBS.some((verb) => lead.startsWith(verb)) && !/^(查重|查错)/.test(lead))
100
+ return "read";
101
+ if (AMBIGUOUS_LEADING_READ.some((verb) => lead.startsWith(verb)) && !WRITE_DESTINATION.test(goal))
102
+ return "read";
80
103
  // No verb: keep the historical build ladder (it is the safe default shape).
81
104
  return "build";
82
105
  }
@@ -465,8 +488,11 @@ const COMPOSER_ROUTES = Object.freeze([
465
488
  summary: "存量模型加字段一条命令:建字段 → 发布 → 重建表单 → 列表追加列;--conditions 固定过滤 + --demo-rows 演示行同链折入——字段+过滤+演示数据的多段需求整句一次问,4-8 次调用合成 1 条命令",
466
489
  // (add verb) × (field noun)——「给既有/存量模型加字段」是变更类需求的最高频动作(r30/r31 探针实证手工链 4 调)
467
490
  groups: [["加", "新增", "添加", "补", "增加"], ["字段"]],
468
- // 只收「加字段本体」;规则/校验/计算/编号/流程语义各有归宿(round10:'给金额字段加自动校验规则' 应归 datarule,不能被本 composer 抢走)
469
- avoid: ["新建模型", "建模型", "从零", "子表", "childFields", "编号规则", "序列号", "规则", "校验", "计算", "默认值", "流程", "权限", "按钮"],
491
+ // 只收「加字段本体」;规则/校验/计算/流程语义各有归宿(round10:'给金额字段加自动校验规则' 应归 datarule,不能被本 composer 抢走)
492
+ // r59: 删掉「编号规则」「序列号」——dry-run 实测 `field-add --fields '[{…seqNoSetting…}]'`
493
+ // 通过(建字段→发布→重建表单→列表加列),这两个词却把「加一个序列号字段」赶去
494
+ // capability/recipe 的 9–12 回合长路。编号/序列号是字段属性,不是另一张能力面。
495
+ avoid: ["新建模型", "建模型", "从零", "子表", "childFields", "规则", "校验", "计算", "默认值", "流程", "权限", "按钮"],
470
496
  topics: ["omc-write-hazards"],
471
497
  },
472
498
  {
@@ -718,6 +744,42 @@ function goalRouteInner(registry, goal) {
718
744
  const availableTopics = new Set(listSkills().map((topic) => topic.name));
719
745
  const mode = detectMode(goal);
720
746
  const readish = mode === "read" || mode === "scout";
747
+ // r60c-F8(真机复现):「按状态分组统计单据条数」被 cue「分组」误路由到 app
748
+ // 写面(app.create/update/delete,write:true)——纯读问句拿到写工具是危险误路由。
749
+ // 聚合/计数问句的正确答案:data 能力**没有 group-by 工具**,诚实指路
750
+ // data.list 拉全量 + `--jq` 投影自行计数;跨模型/大结果集才涉及报表章节。
751
+ // 放在能力打分前,聚合词不再落进任何写阶梯(cue「分组」已从 app 移除)。
752
+ if (readish && /(统计|分组|汇总|聚合|计数|条数|多少条|数一下)/.test(goal) && !WRITE_DESTINATION.test(goal)) {
753
+ const dataRoute = routeById.get("data");
754
+ if (dataRoute !== undefined) {
755
+ const readTools = readToolsInLane(registry, dataRoute.lane);
756
+ const action = readTools.includes("data.list") ? "omc call data.list --args '{\"schemaCode\":\"<模型code>\",\"size\":200}' --jq '.result.items[]'" : "omc commands --capability data";
757
+ return {
758
+ status: "ok",
759
+ goal,
760
+ confident: true,
761
+ mode: "read",
762
+ write: false,
763
+ match: { kind: "capability", ref: "data", title: "运行数据(聚合/计数读路径)", capabilities: ["data"] },
764
+ route: {
765
+ capability: "data",
766
+ lane: dataRoute.lane,
767
+ note: "平台没有 group-by/聚合工具:小结果集用 data.list 拉全量(filter 收窄 + --jq 投影取分组列)后自行计数;跨模型汇总/定时聚合才涉及 report 章节或字段计算(datarule type2)。本路由只读。",
768
+ readTools,
769
+ readiness: DISCOVERY_AUTHORITY.readiness,
770
+ firstCommands: [action],
771
+ write: false,
772
+ readback: true,
773
+ },
774
+ firstAnswer: {
775
+ state: "needs-input",
776
+ question: "要统计哪个模型(schemaCode 或业务名)?按哪个字段分组?",
777
+ action,
778
+ why: "聚合/计数是纯读问句:data 能力无 group-by 工具,data.list 拉全量 + --jq 投影后本地计数是正路(大结果集见 report 章节)",
779
+ },
780
+ };
781
+ }
782
+ }
721
783
  // Known absence only: field-families exposes list/create/update/publish/delete,
722
784
  // with no unpublish endpoint or update status bit (local 1.1.25 probe, 2026-11-11).
723
785
  // Do not infer other absences from tool names: rollback is a top-level command,
@@ -806,7 +868,20 @@ function goalRouteInner(registry, goal) {
806
868
  // 触发词面:条件必填/必填条件/条件显隐/显示条件/隐藏条件/条件只读/只读条件 +
807
869
  // 配置/设置/改成/修改/加上 等写动词,或直接点名 requiredFormula/displayFormula/
808
870
  // readonlyCondition。不提「子表/控件」(那是上一条表单 attributes 的专项路由)。
871
+ // r60a-F1/F2(真机复现):这些 modify 专项路由此前会劫持**整包 build** 问句——
872
+ // 「建模型 …detail 子表(item/qty/price);…列表视图显示…;建字段级规则…」里
873
+ // 「子表…显示…规则」跨三个子句被 /子表.*显示.*规则/ 串成一次命中,整包需求
874
+ // 被当成「改已有表单控件」路由(steps:[],还要一个不存在的 schemaCode)。
875
+ // 护栏一:绿地/整包 build 问句(建模型/新建应用/从零…)不进 modify 专项。
876
+ // 护栏二:关键词必须**同子句**出现(子句内无分隔符、跨度 ≤30 字),
877
+ // 不允许跨「;/,/。」把不同需求缝到一起。
878
+ const greenfieldBuildAsk = /建模型|新建模型|创建模型|搭建|从零|从无到有|一条龙|端到端/.test(goal);
879
+ const clauseLocal = (pattern) => {
880
+ const source = pattern.replace(/\.\*/g, "[^;;,,。]{0,30}");
881
+ return new RegExp(source);
882
+ };
809
883
  if (!/子表/.test(goal)
884
+ && !greenfieldBuildAsk
810
885
  && !/查看|有哪些|是什么|怎么|列出|看看|查询|检查|确认/.test(goal)
811
886
  && (/条件必填|必填条件|条件显隐|显隐条件|显示条件|条件显示|隐藏条件|条件隐藏|条件只读|只读条件|requiredFormula|displayFormula|readonlyCondition/.test(goal))
812
887
  && /配置|设置|改成|修改|加上|加一个|做个|做一|变必填|控制|当.*时/.test(goal)) {
@@ -837,7 +912,7 @@ function goalRouteInner(registry, goal) {
837
912
  },
838
913
  };
839
914
  }
840
- if (/子表|控件/.test(goal) && /子表.*(显示|隐藏|只读|显隐).*(条件|公式|规则)|displayFormula|readonlyFormula/.test(goal)) {
915
+ if (!greenfieldBuildAsk && /子表|控件/.test(goal) && (clauseLocal("子表.*(显示|隐藏|只读|显隐).*(条件|公式|规则)").test(goal) || /displayFormula|readonlyFormula/.test(goal))) {
841
916
  return {
842
917
  status: "ok",
843
918
  goal,
@@ -867,7 +942,14 @@ function goalRouteInner(registry, goal) {
867
942
  // r28c F2: authored recipe aliases beat composers. A short goal like
868
943
  // "按比例赋值" has no capability cue and would otherwise fall through;
869
944
  // "条件成立时按公式赋值" would be stolen by the rule-when composer.
870
- if (!readish) {
945
+ // "按比例赋值" has no capability cue and would otherwise fall through;
946
+ // "条件成立时按公式赋值" would be stolen by the rule-when composer.
947
+ // r31c-F27 回归护栏(r60 P1-11 引入):**显式整包措辞**(从零/一条龙/一整套…)
948
+ // 的问句不能被单配方别名抢走——一条配方代表不了其余能力面。只看
949
+ // WHOLE_APP_CUES 而不用「≥4 能力面」:单配方措辞(「配一条 Create 规则:
950
+ // 调服务按客户名查信用回写」)天然扫过 模型/规则/服务 多个能力面,按面数拦
951
+ // 会把真别名路由也拦掉(bizservice-recipes 别名测试实证)。
952
+ if (!readish && !WHOLE_APP_CUES.some((cue) => goal.includes(cue))) {
871
953
  const aliasHit = bestAliasRecipe(registry, goal);
872
954
  if (aliasHit) {
873
955
  const action = `omc describe ${aliasHit.tool} --example ${aliasHit.recipe}`;
package/dist/graph.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { chmodSync, closeSync, existsSync, mkdirSync, openSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { joinConfigRoot } from "./command-transport.js";
5
5
  import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "./json-column.js";
@@ -65,20 +65,173 @@ export function indexAgeMinutes(pulledAtIso, now = Date.now()) {
65
65
  return 0;
66
66
  return Math.max(0, Math.floor((now - pulled) / 60_000));
67
67
  }
68
- export class GraphIndexAbsentError extends Error {
68
+ /** Base for "the index cannot answer this call" (absent / ambiguous / unreadable). */
69
+ export class GraphIndexError extends Error {
70
+ constructor(message) {
71
+ super(message);
72
+ this.name = "GraphIndexError";
73
+ }
74
+ }
75
+ export class GraphIndexAbsentError extends GraphIndexError {
69
76
  constructor(message) {
70
77
  super(message);
71
78
  this.name = "GraphIndexAbsentError";
72
79
  }
73
80
  }
81
+ /** The file is there but cannot be answered from (corrupt / schema mismatch). */
82
+ export class GraphIndexUnreadableError extends GraphIndexError {
83
+ constructor(message) {
84
+ super(message);
85
+ this.name = "GraphIndexUnreadableError";
86
+ }
87
+ }
74
88
  export class GraphPullLockHeldError extends Error {
75
89
  constructor(message) {
76
90
  super(message);
77
91
  this.name = "GraphPullLockHeldError";
78
92
  }
79
93
  }
80
- export function graphDbPath(root) {
81
- return join(resolve(root ?? process.env.OMC_GRAPH_PATH ?? joinConfigRoot()), ".omc", "graph", "graph.db");
94
+ /** Project root that owns `<root>/.omc/graph/` (explicit > OMC_GRAPH_PATH > config root). */
95
+ export function graphRoot(root) {
96
+ return resolve(root ?? process.env.OMC_GRAPH_PATH ?? joinConfigRoot());
97
+ }
98
+ /**
99
+ * File-name-safe token for an environment name. The common case (ASCII env
100
+ * names) stays human-readable so `ls .omc/graph/` is self-explanatory; names
101
+ * that need rewriting get a digest suffix so two environments can never
102
+ * collapse onto one file.
103
+ */
104
+ export function graphEnvSlug(env) {
105
+ const trimmed = env.trim();
106
+ const safe = trimmed.replace(/[^A-Za-z0-9._-]/g, "-");
107
+ if (safe === trimmed && safe !== "" && safe !== "." && safe !== "..")
108
+ return safe;
109
+ return `${safe === "." || safe === ".." || safe === "" ? "env" : safe}-${sha256(trimmed).slice(0, 6)}`;
110
+ }
111
+ /**
112
+ * `<root>/.omc/graph/<env>.db` — one index per (project, environment).
113
+ *
114
+ * `graph.db` (no env) is the pre-0.6.x slot and stays readable: an upgraded
115
+ * machine keeps answering from it until the next pull, which writes the
116
+ * env-named file and drops the superseded legacy one.
117
+ */
118
+ export function graphDbPath(root, env) {
119
+ const dir = join(graphRoot(root), ".omc", "graph");
120
+ const wanted = env?.trim();
121
+ return join(dir, wanted ? `${graphEnvSlug(wanted)}.db` : "graph.db");
122
+ }
123
+ function metaOf(dbPath) {
124
+ const DatabaseSyncCtor = nodeSqlite().DatabaseSync;
125
+ const db = new DatabaseSyncCtor(dbPath, { readOnly: true });
126
+ try {
127
+ const meta = {};
128
+ for (const row of db.prepare("SELECT key, value FROM meta").all())
129
+ meta[row.key] = row.value;
130
+ meta.__rules = String(db.prepare("SELECT COUNT(*) AS n FROM rules").get().n);
131
+ meta.__models = String(db.prepare("SELECT COUNT(DISTINCT schema_code) AS n FROM rules").get().n);
132
+ return meta;
133
+ }
134
+ finally {
135
+ db.close();
136
+ }
137
+ }
138
+ function describeIndex(dbPath) {
139
+ const legacySlot = dbPath.split(/[\\/]/).pop() === "graph.db";
140
+ const base = { dbPath, dbId: sha256(dbPath).slice(0, 12), legacySlot, ...(existsSync(dbPath) ? { bytes: statSync(dbPath).size } : { bytes: 0 }) };
141
+ try {
142
+ const meta = metaOf(dbPath);
143
+ const pulledAtIso = meta.pulledAtIso ?? "";
144
+ return {
145
+ ...base,
146
+ environmentName: meta.environmentName ?? "",
147
+ projectPath: meta.projectPath ?? dirname(dirname(dirname(dbPath))),
148
+ applicationCode: meta.applicationCode ?? "",
149
+ pulledAtIso,
150
+ ageDays: indexAgeDays(pulledAtIso),
151
+ ageMinutes: indexAgeMinutes(pulledAtIso),
152
+ rules: Number(meta.__rules ?? 0),
153
+ models: Number(meta.__models ?? 0),
154
+ readable: true,
155
+ };
156
+ }
157
+ catch (error) {
158
+ return { ...base, environmentName: "", projectPath: dirname(dirname(dirname(dbPath))), applicationCode: "", pulledAtIso: "", ageDays: 0, ageMinutes: 0, rules: 0, models: 0, readable: false, error: error instanceof Error ? error.message : String(error) };
159
+ }
160
+ }
161
+ /**
162
+ * Every index under one project root. Sorted by environment so the answer is
163
+ * stable; a corrupt file is reported (`readable:false`) rather than skipped —
164
+ * "it exists but I cannot read it" is a different fact from "no index".
165
+ */
166
+ export function listGraphIndexes(root) {
167
+ const dir = join(graphRoot(root), ".omc", "graph");
168
+ if (!existsSync(dir))
169
+ return [];
170
+ let names;
171
+ try {
172
+ names = readdirSync(dir).filter((name) => name.endsWith(".db"));
173
+ }
174
+ catch {
175
+ return [];
176
+ }
177
+ return names
178
+ .map((name) => describeIndex(join(dir, name)))
179
+ .sort((a, b) => (a.environmentName === b.environmentName ? a.dbPath.localeCompare(b.dbPath) : a.environmentName.localeCompare(b.environmentName)));
180
+ }
181
+ /** Human-readable "what can I query here" line, used by every refusal. */
182
+ function availableIndexesHint(root) {
183
+ const entries = listGraphIndexes(root);
184
+ if (entries.length === 0)
185
+ return `该配置根下没有任何索引(${join(graphRoot(root), ".omc", "graph")})`;
186
+ const listed = entries.map((entry) => ` - env=${entry.environmentName || "(不可读)"}${entry.legacySlot ? "(legacy graph.db)" : ""} · ${entry.rules} 规则/${entry.models} 模型 · ${entry.ageMinutes} 分钟前`).join("\n");
187
+ return `可用索引(--env 选择其一):\n${listed}`;
188
+ }
189
+ /**
190
+ * Resolve which file a read opens.
191
+ *
192
+ * - env given: `<env>.db`; if absent, a legacy `graph.db` still answers when its
193
+ * meta says the same environment (upgrade path, no re-pull required).
194
+ * - env omitted: unambiguous only. One index → it; several → refuse with the
195
+ * list instead of picking one (a silent pick is how cross-env answers get
196
+ * mistaken for truth).
197
+ */
198
+ export function resolveGraphDbPath(root, env) {
199
+ const wanted = env?.trim();
200
+ if (wanted) {
201
+ const direct = graphDbPath(root, wanted);
202
+ if (existsSync(direct)) {
203
+ // The file name is a claim, the meta is the truth. A renamed/copied
204
+ // index must not silently answer for an environment it never pulled —
205
+ // resolveGraphDbPath is exported and used directly (e.g. MCP
206
+ // entityInventory), so the guard cannot live only in openGraphIndex.
207
+ const entry = describeIndex(direct);
208
+ if (entry.readable && entry.environmentName && entry.environmentName !== wanted)
209
+ throw new GraphIndexAbsentError(`索引文件 ${direct} 记录的来源环境是「${entry.environmentName}」,不是「${wanted}」;重跑 omc graph pull --env ${wanted}。${availableIndexesHint(root)}`);
210
+ return direct;
211
+ }
212
+ const legacy = graphDbPath(root);
213
+ if (existsSync(legacy) && describeIndex(legacy).environmentName === wanted)
214
+ return legacy;
215
+ throw new GraphIndexAbsentError(`没有环境「${wanted}」的本地索引(${direct});先 omc graph pull --env ${wanted}。${availableIndexesHint(root)}`);
216
+ }
217
+ const legacy = graphDbPath(root);
218
+ const others = listGraphIndexes(root).filter((entry) => !entry.legacySlot);
219
+ if (others.length === 0) {
220
+ if (existsSync(legacy))
221
+ return legacy;
222
+ throw new GraphIndexAbsentError(`没有本地规则图索引(${join(graphRoot(root), ".omc", "graph")});先运行 omc graph pull --env <env> 全量重建`);
223
+ }
224
+ if (others.length === 1)
225
+ return others[0].dbPath;
226
+ const legacyNote = existsSync(legacy) ? `\n另有 legacy graph.db(env=${describeIndex(legacy).environmentName || "不可读"})` : "";
227
+ throw new GraphIndexAmbiguousError(`这个配置根下有 ${others.length} 份索引,必须用 --env 指定查哪一份。${availableIndexesHint(root)}${legacyNote}\n只读清点:omc graph indexes`);
228
+ }
229
+ /** Several indexes live under this root and the caller did not say which. */
230
+ export class GraphIndexAmbiguousError extends GraphIndexError {
231
+ constructor(message) {
232
+ super(message);
233
+ this.name = "GraphIndexAmbiguousError";
234
+ }
82
235
  }
83
236
  /**
84
237
  * Extract api-fact reference edges from one rule's stored node graph. The
@@ -181,7 +334,7 @@ export function extractListViewEdges(schemaCode, viewCode, model) {
181
334
  * `datarule-list`) and vice versa (`rule-list`). Output is sorted so the
182
335
  * published DB is byte-stable regardless of completion order.
183
336
  */
184
- export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRENCY, requestedApplication) {
337
+ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRENCY, requestedApplication, root) {
185
338
  const identity = session.environmentFingerprint();
186
339
  const pulledAtIso = new Date().toISOString();
187
340
  const totalStart = Date.now();
@@ -417,6 +570,10 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
417
570
  identityFingerprint: identity,
418
571
  environmentName: session.environmentName,
419
572
  applicationCode,
573
+ // Point 3: record WHICH project this index belongs to. Env is a platform
574
+ // identity shared by every project that pulls it; without this row two
575
+ // projects' indexes are indistinguishable on the receipt.
576
+ projectPath: graphRoot(root),
420
577
  coverage: { applicationCodes: [applicationCode] },
421
578
  ...(scope !== undefined ? { applicationResolution: applicationResolutionOf(scope) } : {}),
422
579
  pulledAtIso,
@@ -443,8 +600,8 @@ function parseApplicationResolution(raw) {
443
600
  return undefined;
444
601
  }
445
602
  }
446
- function ensureGraphDir() {
447
- const dir = dirname(graphDbPath());
603
+ function ensureGraphDir(dbPath) {
604
+ const dir = dirname(dbPath);
448
605
  mkdirSync(dir, { recursive: true, mode: 0o700 });
449
606
  return dir;
450
607
  }
@@ -453,9 +610,11 @@ function ensureGraphDir() {
453
610
  * considered abandoned and taken over. This is a LOCAL index lock — pull never
454
611
  * writes the environment, so it must not touch the environment write lock.
455
612
  */
456
- async function withGraphPullLock(run) {
457
- ensureGraphDir();
458
- const lockPath = `${graphDbPath()}.lock`;
613
+ async function withGraphPullLock(dbPath, run) {
614
+ ensureGraphDir(dbPath);
615
+ // The lock is PER INDEX FILE: pulling `test` must not block pulling `prod`
616
+ // into the same project (they write different files).
617
+ const lockPath = `${dbPath}.lock`;
459
618
  const owner = `${process.pid} ${new Date().toISOString()}`;
460
619
  let fd;
461
620
  try {
@@ -503,10 +662,13 @@ async function withGraphPullLock(run) {
503
662
  }
504
663
  /** Wholesalerebuild + atomic publish (staging file + rename), 0600. */
505
664
  export async function publishGraphPull(session, concurrency = DEFAULT_PULL_CONCURRENCY, options = {}) {
665
+ // The environment decides the file: one project can index `test` and `prod`
666
+ // side by side, so the target is not known until the session resolves.
667
+ const dbPath = graphDbPath(options.root, session.environmentName);
506
668
  try {
507
- return await withGraphPullLock(async () => {
669
+ return await withGraphPullLock(dbPath, async () => {
508
670
  const requested = options.applicationCodes?.length ? options.applicationCodes : [undefined];
509
- const parts = await Promise.all(requested.map((application) => pullRuleGraph(session, concurrency, application)));
671
+ const parts = await Promise.all(requested.map((application) => pullRuleGraph(session, concurrency, application, options.root)));
510
672
  const first = parts[0];
511
673
  const data = parts.length === 1 ? first : {
512
674
  ...first,
@@ -520,7 +682,7 @@ export async function publishGraphPull(session, concurrency = DEFAULT_PULL_CONCU
520
682
  scanned: parts.reduce((sum, part) => ({ models: sum.models + part.scanned.models, rules: sum.rules + part.scanned.rules, datarules: sum.datarules + part.scanned.datarules, views: sum.views + part.scanned.views, parseFailures: sum.parseFailures + part.scanned.parseFailures }), { models: 0, rules: 0, datarules: 0, views: 0, parseFailures: 0 }),
521
683
  timings: { listMs: parts.reduce((n, part) => n + part.timings.listMs, 0), readMs: parts.reduce((n, part) => n + part.timings.readMs, 0), totalMs: parts.reduce((n, part) => n + part.timings.totalMs, 0) },
522
684
  };
523
- const staging = `${graphDbPath()}.staging-${process.pid}`;
685
+ const staging = `${dbPath}.staging-${process.pid}`;
524
686
  rmSync(staging, { force: true });
525
687
  const DatabaseSyncCtor = nodeSqlite().DatabaseSync;
526
688
  const db = new DatabaseSyncCtor(staging);
@@ -597,20 +759,31 @@ export async function publishGraphPull(session, concurrency = DEFAULT_PULL_CONCU
597
759
  }
598
760
  chmodSync(staging, 0o600);
599
761
  const dbBytes = statSync(staging).size;
600
- renameSync(staging, graphDbPath());
762
+ renameSync(staging, dbPath);
763
+ // Upgrade path: a legacy `graph.db` holding the SAME environment is now
764
+ // superseded by `<env>.db`. Leaving it behind would make a no-`--env` read
765
+ // ambiguous (two files, one environment). Best effort, never fatal.
766
+ const legacy = graphDbPath();
767
+ if (legacy !== dbPath) {
768
+ try {
769
+ if (existsSync(legacy) && describeIndex(legacy).environmentName === data.meta.environmentName)
770
+ unlinkSync(legacy);
771
+ }
772
+ catch { /* keep both rather than fail a successful pull */ }
773
+ }
601
774
  return { ...data, dbBytes };
602
775
  });
603
776
  }
604
777
  catch (error) {
605
778
  // A failed build must not leave staging garbage next to the index.
606
- rmSync(`${graphDbPath()}.staging-${process.pid}`, { force: true });
779
+ rmSync(`${dbPath}.staging-${process.pid}`, { force: true });
607
780
  throw error;
608
781
  }
609
782
  }
610
- function openGraphIndex() {
611
- const dbPath = graphDbPath();
783
+ function openGraphIndex(selector = {}) {
784
+ const dbPath = resolveGraphDbPath(selector.root, selector.env);
612
785
  if (!existsSync(dbPath))
613
- throw new GraphIndexAbsentError("没有本地规则图索引(<配置根>/.omc/graph/graph.db);先运行 omc graph pull --env <env> 全量重建");
786
+ throw new GraphIndexAbsentError(`没有本地规则图索引(${dbPath});先运行 omc graph pull --env <env> 全量重建`);
614
787
  let db;
615
788
  try {
616
789
  const DatabaseSyncCtor = nodeSqlite().DatabaseSync;
@@ -619,7 +792,12 @@ function openGraphIndex() {
619
792
  for (const row of db.prepare("SELECT key, value FROM meta").all())
620
793
  meta[row.key] = row.value;
621
794
  if (meta.schemaVersion !== GRAPH_SCHEMA_VERSION)
622
- throw new GraphIndexAbsentError(`索引 schema 版本不匹配(${meta.schemaVersion ?? "unknown"} ≠ ${GRAPH_SCHEMA_VERSION});当前版本需要 schema ${GRAPH_SCHEMA_VERSION},旧版索引已作废,请重跑 omc graph pull(schema 升版需重拉)`);
795
+ throw new GraphIndexUnreadableError(`索引 schema 版本不匹配(${meta.schemaVersion ?? "unknown"} ≠ ${GRAPH_SCHEMA_VERSION});当前版本需要 schema ${GRAPH_SCHEMA_VERSION},旧版索引已作废,请重跑 omc graph pull(schema 升版需重拉)`);
796
+ // An env-named file that says a different environment is a stale/renamed
797
+ // fixture, not an answer. Refuse rather than silently cross environments.
798
+ const wanted = selector.env?.trim();
799
+ if (wanted && meta.environmentName && meta.environmentName !== wanted)
800
+ throw new GraphIndexAbsentError(`索引文件 ${dbPath} 记录的来源环境是「${meta.environmentName}」,不是「${wanted}」;重跑 omc graph pull --env ${wanted}。${availableIndexesHint(selector.root)}`);
623
801
  const ruleCount = db.prepare("SELECT COUNT(*) AS n FROM rules").get().n;
624
802
  const modelCount = db.prepare("SELECT COUNT(DISTINCT schema_code) AS n FROM rules").get().n;
625
803
  const entityCounts = {
@@ -664,8 +842,14 @@ function openGraphIndex() {
664
842
  const coverage = { applicationCodes, ...(tenantApplications ? { tenantApplications } : {}), fields: { coveredApplications: fieldApplications, notCovered: applicationCodes.filter((code) => !fieldApplications.includes(code)), countsByApplication } };
665
843
  return {
666
844
  db,
845
+ dbPath,
667
846
  summary: {
668
847
  environmentName: meta.environmentName ?? "",
848
+ // Point 3: the answer carries its own provenance. A pre-0.6.x index
849
+ // has no projectPath row — derive it from the DB location instead of
850
+ // claiming "unknown", and never require a re-pull for this.
851
+ projectPath: meta.projectPath ?? dirname(dirname(dirname(dbPath))),
852
+ dbId: sha256(dbPath).slice(0, 12),
669
853
  applicationCode: meta.applicationCode ?? "",
670
854
  coverage,
671
855
  // Persisted as JSON by the writer; a legacy index (pre-0.5.4) has no
@@ -692,7 +876,7 @@ function openGraphIndex() {
692
876
  }
693
877
  catch (error) {
694
878
  db?.close();
695
- throw error instanceof GraphIndexAbsentError ? error : new GraphIndexAbsentError(`索引不可读(schema 不匹配或文件损坏):${error instanceof Error ? error.message : String(error)};重跑 omc graph pull`);
879
+ throw error instanceof GraphIndexError ? error : new GraphIndexUnreadableError(`索引不可读(schema 不匹配或文件损坏):${error instanceof Error ? error.message : String(error)};重跑 omc graph pull`);
696
880
  }
697
881
  }
698
882
  /**
@@ -750,8 +934,8 @@ function splitScopedCode(code) {
750
934
  return null; // 只认一层 a.b
751
935
  return { schemaCode, code: bare };
752
936
  }
753
- export function queryGraphReferences(kind, rawCode) {
754
- const { db, summary } = openGraphIndex();
937
+ export function queryGraphReferences(kind, rawCode, selector = {}) {
938
+ const { db, summary } = openGraphIndex(selector);
755
939
  try {
756
940
  // 字段可带宿主模型限定(`crm_contract.contract_no`):只认字段面——
757
941
  // model/service 的 code 本身含点会歧义,那里保持原样查询。
@@ -811,8 +995,8 @@ export function queryGraphReferences(kind, rawCode) {
811
995
  db.close();
812
996
  }
813
997
  }
814
- export function queryGraphReferencesBatch(kind, codes) {
815
- const { db, summary } = openGraphIndex();
998
+ export function queryGraphReferencesBatch(kind, codes, selector = {}) {
999
+ const { db, summary } = openGraphIndex(selector);
816
1000
  try {
817
1001
  const wanted = [...new Set(codes.filter(Boolean))];
818
1002
  const rows = wanted.length === 0 ? [] : db.prepare(`SELECT code, schema_code, rule_code, node_code, node_type, via FROM edges WHERE kind = ? AND code IN (${wanted.map(() => "?").join(",")}) ORDER BY code, schema_code, rule_code, node_code, via`).all(kind, ...wanted);
@@ -822,8 +1006,8 @@ export function queryGraphReferencesBatch(kind, codes) {
822
1006
  db.close();
823
1007
  }
824
1008
  }
825
- export function queryGraphEdges(fromSchema, toSchema, kind, offset = 0, limit = 50) {
826
- const { db, summary } = openGraphIndex();
1009
+ export function queryGraphEdges(fromSchema, toSchema, kind, offset = 0, limit = 50, selector = {}) {
1010
+ const { db, summary } = openGraphIndex(selector);
827
1011
  try {
828
1012
  const conditions = [];
829
1013
  const params = [];
@@ -849,20 +1033,25 @@ export function queryGraphEdges(fromSchema, toSchema, kind, offset = 0, limit =
849
1033
  db.close();
850
1034
  }
851
1035
  }
852
- export function readGraphStatus() {
853
- const { db, summary } = openGraphIndex();
1036
+ export function readGraphStatus(selector = {}) {
1037
+ const { db, dbPath, summary } = openGraphIndex(selector);
854
1038
  try {
855
1039
  const gaps = db.prepare("SELECT kind, ref, note FROM gaps ORDER BY kind, ref LIMIT 50").all();
856
- const dbPath = graphDbPath();
1040
+ const projectRoot = summary.projectPath || dirname(dirname(dirname(dbPath)));
1041
+ const otherIndexes = listGraphIndexes(selector.root).filter((entry) => entry.dbPath !== dbPath);
857
1042
  return {
858
1043
  index: summary,
859
1044
  dbBytes: statSync(dbPath).size,
860
1045
  dbPath,
861
1046
  dbId: sha256(dbPath).slice(0, 12),
862
- mcpHint: `MCP 工具按注册时的 --path 读库(当前索引根:${dirname(dirname(dbPath))});要让 MCP 看到本次拉取,请执行 omc graph pull --path ${dirname(dirname(dbPath))} --env <env>。`,
1047
+ mcpHint: `MCP 用 --path 指向项目根、用 env 参数选索引(本项目根:${projectRoot};当前 env=${summary.environmentName || "?"})。要让 MCP 看到本次拉取,执行 omc graph pull --path ${projectRoot} --env ${summary.environmentName || "<env>"}。`,
863
1048
  ageMinutes: summary.ageMinutes,
864
1049
  staleAfterMinutes: summary.staleAfterMinutes,
865
1050
  ...(summary.staleWarning ? { warning: summary.staleWarning } : {}),
1051
+ // One project, several environments: status must say what ELSE is
1052
+ // queryable here, otherwise the caller cannot discover the sibling index
1053
+ // without guessing a file name.
1054
+ ...(otherIndexes.length > 0 ? { otherIndexes: otherIndexes.map((entry) => ({ environmentName: entry.environmentName, dbId: entry.dbId, pulledAtIso: entry.pulledAtIso, ageMinutes: entry.ageMinutes, rules: entry.rules, models: entry.models })) } : {}),
866
1055
  coverage: summary.coverage,
867
1056
  coveredApplications: summary.coverage.applicationCodes,
868
1057
  tenantApplications: summary.coverage.tenantApplications ?? summary.coverage.applicationCodes,
@@ -880,8 +1069,8 @@ export function readGraphStatus() {
880
1069
  * a prefix match (`引用*`), which is also what makes CJK usable: unicode61
881
1070
  * stores a CJK run as one token, so a full-run query hits only by prefix.
882
1071
  */
883
- export function searchGraphRules(term, limit = 20, offset = 0) {
884
- const { db, summary } = openGraphIndex();
1072
+ export function searchGraphRules(term, limit = 20, offset = 0, selector = {}) {
1073
+ const { db, summary } = openGraphIndex(selector);
885
1074
  try {
886
1075
  const tokens = term.trim().split(/\s+/).filter((token) => token !== "");
887
1076
  let matches = [];
@@ -960,8 +1149,8 @@ export function searchGraphRules(term, limit = 20, offset = 0) {
960
1149
  * read/write these codes — verify those too." Bounded: 50 rules, 20 codes per
961
1150
  * kind; the same fail-closed gap semantics as references apply.
962
1151
  */
963
- export function impactGraph(kind, code) {
964
- const { db, summary } = openGraphIndex();
1152
+ export function impactGraph(kind, code, selector = {}) {
1153
+ const { db, summary } = openGraphIndex(selector);
965
1154
  try {
966
1155
  const hop1 = db
967
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")
@@ -74,6 +74,12 @@ function expectedFieldOptions(schemaCode, field) {
74
74
  * (observed 2026-09-27: `field.list` briefly reported options:null for a row
75
75
  * that had them, and the final readback called the intent equivalent) is
76
76
  * reported as converged — the agent then discovers it at runtime instead.
77
+ *
78
+ * r60a-F8 guard: the expected side is what the WRITE SEAM would send. When a
79
+ * declared key is absent from that projection (seam drops it — e.g. the
80
+ * CHILD_TABLE parent row carries no options at all) the old null==null
81
+ * comparison called the intent equivalent while nothing landed. Such keys now
82
+ * emit `field-option-unwritable` instead of comparing two nulls.
77
83
  */
78
84
  function compareFieldOptions(schemaCode, field, live, emit) {
79
85
  const keys = declaredOptionKeys(field);
@@ -82,6 +88,13 @@ function compareFieldOptions(schemaCode, field, live, emit) {
82
88
  const resource = `field:${schemaCode}.${field.code}`;
83
89
  const expected = expectedFieldOptions(schemaCode, field);
84
90
  const liveOptions = (live.options ?? {});
91
+ // r60a-F8 防假等价:声明的 options 键若写入缝根本不会发送(expected 缺该键,
92
+ // 或整形状被写缝拒绝 → expected undefined),「声明了但没落地」不能判等价——
93
+ // 此前 expected/live 双 null 相等,把静默丢键当成了已达标。
94
+ if (expected === undefined) {
95
+ emit.difference("field-option-unwritable", resource, `字段 ${resource} 声明了 options(${keys.join("、")}),但写入缝拒绝该形状(族形状校验未过)——声明不会落地,readback 不判等价`);
96
+ return;
97
+ }
85
98
  for (const key of keys) {
86
99
  if (key === "optionsSet") {
87
100
  const customCodes = (value) => {
@@ -94,6 +107,10 @@ function compareFieldOptions(schemaCode, field, live, emit) {
94
107
  emit.difference("field-options-mismatch", resource, `字段 ${resource} 的 choices 与 live 不一致(live=${canonicalJson(got)} intent=${canonicalJson(want)})`);
95
108
  continue;
96
109
  }
110
+ if (!(key in expected)) {
111
+ emit.difference("field-option-unwritable", resource, `字段 ${resource} 声明了 options.${key},但写入缝不会发送该键(子表父行/族形状不接受)——声明不会落地;门户条件走表单面(form.draft 改控件 attributes 后 form.publish)`);
112
+ continue;
113
+ }
97
114
  if (canonicalJson(expected?.[key] ?? null) !== canonicalJson(liveOptions[key] ?? null))
98
115
  emit.difference("field-options-mismatch", resource, `字段 ${resource} 的 options.${key} 与 live 不一致(live=${canonicalJson(liveOptions[key] ?? null)} intent=${canonicalJson(expected?.[key] ?? null)})`);
99
116
  }
@@ -365,6 +382,13 @@ export const fieldCapability = {
365
382
  if (relationField && relativeValue === undefined && !(optionsNode?.kind === "map" && toPlain(optionsNode).relativeCode !== undefined))
366
383
  pushError(ctx, "intent-field-relativecode-required", `关联字段(${fieldType})必须给 relativeCode(目标模型 code);可写在字段顶层或 options.relativeCode`, `${fieldBase}.relativeCode`, "value");
367
384
  const explicitOptions = optionsNode?.kind === "map" ? toPlain(optionsNode) : {};
385
+ // r60a-F8(真机实测):CHILD_TABLE 父行的 options 在写入缝被整体丢弃
386
+ // (prepareFieldChange 子表分支返回 options:{},wire body 不带 options 键),
387
+ // 而 readback 的 expected 同样为空 → null==null 假等价。离线拒绝,
388
+ // 并把真正可行的通道(表单 attributes 面)写进消息。
389
+ if (fieldType === "CHILD_TABLE" && Object.keys(explicitOptions).length > 0) {
390
+ pushError(ctx, "intent-field-option-unsupported", `子表字段(CHILD_TABLE)父行不接受 options(声明了 ${Object.keys(explicitOptions).join("、")})——平台建列时整体丢弃,且 readback 判等会漏检(r60a-F8)。门户条件(requiredFormula/readonlyFormula/displayFormula)走表单面:form.get --controls 读 draftAttributesJson 定位控件 → form.draft 改该控件 → form.publish;子表**列级** options 写在各子列的 options`, `${fieldBase}.options`, "value");
391
+ }
368
392
  // A choice family's allowed values live in TOP-LEVEL `choices` (the
369
393
  // compiler synthesizes the platform's optionsSet). Callers habitually
370
394
  // try `options.items` / `options.choices`, which the option passthrough
@@ -43,16 +43,23 @@ export function intentWarnings(intent) {
43
43
  // control had no requiredFormula; the live portal did not require it). The
44
44
  // portal-facing condition must be declared in `fields[].options`.
45
45
  for (const datarule of model.datarules ?? []) {
46
- if ([3, 4, 5].includes(datarule.dataRuleType))
46
+ const field = model.fields.find((candidate) => candidate.code === datarule.propertyCode);
47
+ if ([3, 4, 5].includes(datarule.dataRuleType)) {
48
+ // r60a-F11(真机复现):propertyCode 是 CHILD_TABLE 父字段时,下面那句
49
+ // 「写到 fields[].options」是死路——子表父行不接受 options(写入缝整体
50
+ // 丢弃,readback 还会假等价,r60a-F8)。按字段类型分叉给真通道。
51
+ const childTableTarget = field?.type === "CHILD_TABLE";
47
52
  warnings.push({
48
53
  resource: `datarule:${model.code}.${datarule.propertyCode}`,
49
54
  code: "datarule-not-portal-facing",
50
- message: `字段级数据规则 type ${datarule.dataRuleType}(${datarule.dataRuleType === 4 ? "条件必填" : datarule.dataRuleType === 5 ? "条件只读" : "文本拼接"})不驱动门户表单控件:平台把它存成 bizdatarule、只镜像进控件 historyOpt,而运行时门户读控件 options(真机复核:规则已存但发布控件无该字段、门户不拦)。要让门户生效,把条件写到字段的 options 里(fields[].options.requiredFormula / readonlyCondition / shortTextStitch)——这条路径已真机验证可穿透到发布控件;datarule 只留给服务端字段级引擎(校验/计算)。`,
55
+ message: childTableTarget
56
+ ? `字段级数据规则 type ${datarule.dataRuleType}(${datarule.dataRuleType === 4 ? "条件必填" : datarule.dataRuleType === 5 ? "条件只读" : "文本拼接"})不驱动门户表单控件;且 ${datarule.propertyCode} 是子表(CHILD_TABLE)父字段——fields[].options 对子表父行**不生效**(写入缝丢弃,真机 r60a-F8)。门户条件走表单 attributes 面:form.get --controls 读 draftAttributesJson 定位控件 → form.draft 改该控件的 requiredFormula/readonlyFormula/displayFormula → form.publish。`
57
+ : `字段级数据规则 type ${datarule.dataRuleType}(${datarule.dataRuleType === 4 ? "条件必填" : datarule.dataRuleType === 5 ? "条件只读" : "文本拼接"})不驱动门户表单控件:平台把它存成 bizdatarule、只镜像进控件 historyOpt,而运行时门户读控件 options(真机复核:规则已存但发布控件无该字段、门户不拦)。要让门户生效,把条件写到字段的 options 里(fields[].options.requiredFormula / readonlyCondition / shortTextStitch)——这条路径已真机验证可穿透到发布控件;datarule 只留给服务端字段级引擎(校验/计算)。`,
51
58
  });
59
+ }
52
60
  // Dual-write advisory (dogfood R1): when the SAME field already declares
53
61
  // the portal-facing condition in `fields[].options`, the datarule row is
54
62
  // redundant. Surface it rather than silently writing both.
55
- const field = model.fields.find((candidate) => candidate.code === datarule.propertyCode);
56
63
  const fieldOptions = field?.options ?? {};
57
64
  const duplicateKey = datarule.dataRuleType === 4 ? "requiredFormula" : datarule.dataRuleType === 5 ? "readonlyCondition" : undefined;
58
65
  if (duplicateKey !== undefined && fieldOptions[duplicateKey] !== undefined)