@stalfh233/omc-cli 0.6.47 → 0.6.49

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 (43) hide show
  1. package/dist/capability-overview.js +113 -0
  2. package/dist/cli-stdout.js +3 -0
  3. package/dist/cli.js +251 -60
  4. package/dist/command-transport.js +5 -1
  5. package/dist/discovery.js +193 -75
  6. package/dist/goal-plan.js +1244 -0
  7. package/dist/goal-routes.js +28 -2
  8. package/dist/graph.js +223 -34
  9. package/dist/lanes/app.js +4 -0
  10. package/dist/lanes/apply-changes.js +1 -0
  11. package/dist/lanes/b2-registration.js +24 -0
  12. package/dist/lanes/businessrule.js +5 -0
  13. package/dist/lanes/custom-page.js +8 -0
  14. package/dist/lanes/datarule.js +4 -0
  15. package/dist/lanes/dictionary.js +13 -0
  16. package/dist/lanes/environment.js +2 -0
  17. package/dist/lanes/field.js +5 -0
  18. package/dist/lanes/folder.js +4 -0
  19. package/dist/lanes/form.js +5 -0
  20. package/dist/lanes/list-view.js +5 -0
  21. package/dist/lanes/meta.js +5 -0
  22. package/dist/lanes/model.js +9 -0
  23. package/dist/lanes/online-js.js +2 -0
  24. package/dist/lanes/organization.js +20 -0
  25. package/dist/lanes/perm.js +5 -5
  26. package/dist/lanes/programming.js +6 -0
  27. package/dist/lanes/report.js +9 -0
  28. package/dist/lanes/rule-lifecycle.js +6 -0
  29. package/dist/lanes/rulelog.js +1 -0
  30. package/dist/lanes/runtime-data.js +6 -0
  31. package/dist/lanes/workflow.js +18 -0
  32. package/dist/mcp-graph.js +180 -41
  33. package/dist/package-tool.js +1 -0
  34. package/dist/search-index.js +137 -0
  35. package/dist/tool-search.js +647 -0
  36. package/dist/tools.js +1 -0
  37. package/dist/write.js +2 -1
  38. package/docs/omc-introduction.md +5 -7
  39. package/package.json +6 -5
  40. package/skills/omc-business-configuration.md +2 -1
  41. package/skills/omc-capabilities.md +3 -2
  42. package/skills/omc-start-here.md +21 -7
  43. package/skills/omc-tool-selection.md +7 -15
@@ -0,0 +1,647 @@
1
+ const ACTION_VERBS = Object.freeze({
2
+ create: "create", register: "create", import: "create", submit: "create",
3
+ save: "upsert",
4
+ get: "read", list: "read", load: "read", search: "read", tree: "read",
5
+ references: "read", inspect: "read", export: "read", check: "read", validate: "read",
6
+ update: "update", publish: "update", enable: "update", disable: "update",
7
+ move: "update", draft: "update", compose: "update", run: "update", link: "update",
8
+ assign: "update", test: "update", bindRule: "update", setButtons: "update",
9
+ addPermission: "update", setUserScope: "update", transferDepartment: "update",
10
+ setSummary: "update", runButton: "update", commit: "update", start: "update", addUsers: "update",
11
+ delete: "delete", deleteMany: "delete", disableMany: "delete",
12
+ removeUsers: "delete", removePermission: "delete",
13
+ });
14
+ /**
15
+ * 查询里的意图词 → 意图类(中文业务说法)。单字「查/加/改/删」也在内。
16
+ *
17
+ * `weak: true` = 这个词在中文里**经常是名词**(「设计**配置**」「发布**状态**」「保存**值**」),
18
+ * 单独出现不足以判定写意图:它的对齐分减半,且不与强读意图争夺「读主句」。
19
+ * 没有这条,「把模型的设计配置取回来」会被判成写(HB02,holdout 实测)。
20
+ */
21
+ const INTENT_WORDS = Object.freeze([
22
+ { word: "查看", cls: "read" }, { word: "列出", cls: "read" }, { word: "检索", cls: "read" },
23
+ { word: "搜索", cls: "read" }, { word: "检查", cls: "read" }, { word: "查询", cls: "read" },
24
+ { word: "获取", cls: "read" }, { word: "读", cls: "read" }, { word: "查", cls: "read" }, { word: "看", cls: "read" }, { word: "列", cls: "read" },
25
+ // M1 泛化修正(holdout 暴露):中文读请求经常**不带读动词**——「都有什么模型」
26
+ // 「把配置取回来」「拿字典的编码」。缺这些词时读意图为空,写意图(「配置」
27
+ // 「设计」里的动词)会独占候选,读查询被推给写工具(安全门 43.8% 红)。
28
+ { word: "取回", cls: "read" }, { word: "取", cls: "read" }, { word: "拿", cls: "read" },
29
+ { word: "有哪些", cls: "read" }, { word: "有什么", cls: "read" }, { word: "都有什么", cls: "read" },
30
+ { word: "哪些", cls: "read" },
31
+ { word: "都有哪些", cls: "read" }, { word: "多少", cls: "read" }, { word: "几个", cls: "read" },
32
+ { word: "成了吗", cls: "read" }, { word: "发布没有", cls: "read" },
33
+ { word: "新增", cls: "create" }, { word: "创建", cls: "create" }, { word: "新建", cls: "create" },
34
+ { word: "注册", cls: "create" }, { word: "添加", cls: "create" }, { word: "增加", cls: "create" }, { word: "补", cls: "create" }, { word: "建", cls: "create" }, { word: "加", cls: "create" },
35
+ { word: "修改", cls: "update" }, { word: "更新", cls: "update", weak: true }, { word: "配置", cls: "update", weak: true },
36
+ { word: "设置", cls: "update", weak: true }, { word: "绑定", cls: "update" }, { word: "启用", cls: "update" },
37
+ { word: "停用", cls: "update" }, { word: "发布", cls: "update", weak: true }, { word: "保存", cls: "upsert", weak: true },
38
+ { word: "测试", cls: "update" }, { word: "试跑", cls: "update" }, { word: "改", cls: "update" },
39
+ // M1-2d(族 C):这些中文动作原来一个都不在表里,`transferDepartment` /
40
+ // `removePermission` / `setButtons` / `move` / `commit` 因此只能靠对象段命中。
41
+ { word: "转到", cls: "update" }, { word: "挪到", cls: "update" }, { word: "移到", cls: "update" },
42
+ { word: "撤销", cls: "update" }, { word: "勾选", cls: "update" }, { word: "提交", cls: "update" },
43
+ { word: "设置", cls: "update" },
44
+ { word: "删除", cls: "delete" }, { word: "清空", cls: "delete" }, { word: "移除", cls: "delete" }, { word: "删", cls: "delete" },
45
+ // 「撤销」是**撤回**语义(撤销权限/撤销授权),归 delete:否则 removePermission
46
+ // 这类工具会被 destructive 惩罚压出结果,而 addPermission 顶上去(W13)。
47
+ { word: "撤销", cls: "delete" }, { word: "收回", cls: "delete" },
48
+ ]);
49
+ /**
50
+ * 动作段词典(M1-2a/族 A):名字里的**动作段**(`move` / `transferDepartment` /
51
+ * `setButtons` / `addPermission` / `commit` / `inspect` …)对应的中文说法。
52
+ *
53
+ * 为什么需要它:`rule.disable` 与 `rule.node.update` 的动作类都是 `update`,
54
+ * `model.update` 与 `model.move` 也是——意图类把「怎么改」抹平了,于是同分退化成
55
+ * 名字序。这里按**动作段本身**给分,把「改名」和「挪到」区分开。
56
+ *
57
+ * 与 `search.intents` 的分工:别名是**工具级**业务原话,
58
+ * 这里是**段级**动作词,一个词修一族工具(所有 `*.list` / `*.destroy`)。
59
+ */
60
+ const ACTION_SEGMENT_LEXICON = Object.freeze({
61
+ update: ["改名", "改个名字", "改名字", "重命名", "改名称", "换个名字", "写正文", "写页面正文", "改正文", "写页面"],
62
+ move: ["挪到", "移到", "移动到", "换个分组", "挪个位置"],
63
+ transferDepartment: ["转到别的部门", "转到其他部门", "调岗", "转部门", "转移到部门", "转到", "调走", "调离", "换部门"],
64
+ addPermission: ["加发起权限", "加权限", "授予权限", "授权发起", "发起权限"],
65
+ removePermission: ["撤销权限", "撤销发起权限", "取消权限", "取消发起权限", "收回权限", "收回来", "收回"],
66
+ setButtons: ["勾选按钮", "勾选", "表单操作按钮", "按钮权限", "设按钮", "表单按钮"],
67
+ commit: ["提交配置", "保存配置", "提交环境"],
68
+ start: ["配置引导", "初始化配置", "带我配置", "一步步配置", "环境还没配置"],
69
+ inspect: ["全部读出来", "一次读全", "综合看", "整体看", "全部读出", "一次拿全"],
70
+ runButton: ["点一下按钮", "点按钮", "执行按钮", "工具栏按钮", "点一下", "工具栏"],
71
+ node: ["节点", "节点条件"],
72
+ tree: ["目录结构", "目录树", "树形结构"],
73
+ instanceActivity: ["实例节点", "节点状态", "实例状态", "实例每个节点"],
74
+ status: ["停用记录", "启用记录", "停用字典", "启用字典", "停用一条"],
75
+ parent: ["父节点下", "子记录", "下级记录"],
76
+ records: ["字典记录", "字典明细", "字典条目"],
77
+ classes: ["字典分类", "分类详情"],
78
+ names: ["名称摘要", "名字摘要", "id 和名称"],
79
+ type: ["按字典类型", "字典类型", "按类型"],
80
+ schemas: ["有哪些模型有源码", "源码清单", "模型源码"],
81
+ sources: ["源码清单", "模型下源码"],
82
+ compile: ["编译检查"],
83
+ get: ["取源码", "读源码", "源码草稿", "源码的草稿"],
84
+ usage: ["使用标记", "标记使用", "设置使用标记"],
85
+ enable: ["启用", "开启", "打开"],
86
+ disable: ["停用", "关闭", "禁用"],
87
+ });
88
+ /**
89
+ * 松散包含(M1-2a):短语的字符按顺序出现、中间总间隙 ≤ `maxGap` 即算命中。
90
+ *
91
+ * 为什么需要:「撤销**流程的发起**权限」与词典里的「撤销发起权限」中间隔了 5 个字,
92
+ * 严格 `includes` 匹配不上;这类插入语(「流程的」「字典里的」)在中文需求里很常见。
93
+ * 只对**动作段/长短语**启用,且要求短语 ≥2 字,避免宽词误命中。
94
+ */
95
+ function containsLoose(text, phrase, maxGap) {
96
+ if (phrase.length < 2)
97
+ return false;
98
+ if (text.includes(phrase))
99
+ return true;
100
+ // 短语越短,允许的插入语越少——「点一下…(表单工具栏)…按钮」不该算命中
101
+ // 「点按钮」,而「撤销…(流程的发起)…权限」应该算命中「撤销权限」(W14/W13)。
102
+ const gapBudget = maxGap ?? (phrase.length <= 3 ? 3 : 6);
103
+ let cursor = 0;
104
+ let gap = 0;
105
+ for (const char of phrase) {
106
+ const at = text.indexOf(char, cursor);
107
+ if (at < 0)
108
+ return false;
109
+ if (cursor > 0)
110
+ gap += at - cursor;
111
+ if (gap > gapBudget)
112
+ return false;
113
+ cursor = at + 1;
114
+ }
115
+ return true;
116
+ }
117
+ /**
118
+ * 「要清单」的词(M1-2d):查询带这些词且是**读意图**时,同为读动作的 `list` 段
119
+ * 压过 `get` 段(「模型下有哪些列表视图」→ listview.list,不是 listview.get)。
120
+ *
121
+ * 刻意不收裸「列表」:它是对象词「列表视图」的一部分,「删掉列表视图」会被误判成
122
+ * 要清单(实测把 listview.delete 的 top1 抢给了 listview.list)。
123
+ */
124
+ const COLLECTION_WORDS = Object.freeze([
125
+ "有哪些", "有哪", "清单", "全部", "所有", "都哪些", "列一下", "列出", "一共几个", "哪些",
126
+ "都有什么", "有什么", "多少", "几个", "几套",
127
+ ]);
128
+ /** 单数标记:带这些词时不要清单(「读**一个**列表视图」「这**条**记录」)。 */
129
+ const SINGULAR_MARKERS = Object.freeze(["一个", "一条", "某个", "这条", "那条", "单条", "这条"]);
130
+ /**
131
+ * 读意图主句判定(评审 P1-2 的延伸,M1-2d 族 D):查询**以读动词开头**时,
132
+ * 读意图是主语义,句中的「发布/配置」这类词多是名词短语的一部分
133
+ * (「读一下表单的**发布状态**和控件」)。此时写意图不再给对齐分,
134
+ * 否则 form.draft 会压过 form.get,读查询被推给写工具(安全门红)。
135
+ */
136
+ const READ_LEADING_VERBS = Object.freeze(["读", "看", "查", "列出", "列", "检索", "搜索", "获取", "找"]);
137
+ /**
138
+ * 对象词表:工具名对象段(英文)→ 业务说法。检索时反向查(查询文本里出现
139
+ * 哪个中文对象词 / 英文段),「方法」「连接池」这类词才能落到 method.*、
140
+ * service.dbconnpool.*。刻意**不收**裸「数据」(太宽,靠能力标题/摘要兜底)。
141
+ */
142
+ const OBJECT_LEXICON = Object.freeze({
143
+ model: ["模型", "业务模型"],
144
+ field: ["字段"],
145
+ form: ["表单"],
146
+ listview: ["列表视图", "列表", "视图", "查询列"],
147
+ datarule: ["字段级规则", "数据规则", "校验规则", "控件规则", "字段校验", "字段级校验"],
148
+ rule: ["业务规则", "规则"],
149
+ rulelog: ["规则执行日志", "规则日志", "执行日志", "触发日志"],
150
+ workflow: ["审批流程", "审批流", "工作流", "流程模板", "流程"],
151
+ workitem: ["待办", "工单"],
152
+ role: ["角色"],
153
+ roleGroup: ["角色组"],
154
+ department: ["部门"],
155
+ user: ["用户", "员工", "账号", "成员"],
156
+ dictionary: ["数据字典", "字典", "选项"],
157
+ report: ["报表", "图表", "看板"],
158
+ data: ["业务数据", "运行数据", "记录", "单据"],
159
+ service: ["集成服务", "业务服务", "服务"],
160
+ method: ["接口方法", "接口", "方法"],
161
+ category: ["所属目录", "分类", "类别"],
162
+ dbconnpool: ["数据库连接池", "连接池"],
163
+ onlinejs: ["在线js", "在线JS", "脚本"],
164
+ programming: ["在线编码", "在线开发", "后端源码", "java源码", "在线源码", "在线代码", "在线代码"],
165
+ app: ["应用", "门户"],
166
+ // M1-2b(族 B 铁证):原来只有「文件夹」「目录树」,用户说的「目录」「分组」
167
+ // 一个都不在——三条目录查询因此 0 命中。补词而非新建键(键已存在)。
168
+ folder: ["文件夹", "目录树", "应用树", "目录", "分组"],
169
+ custompage: ["自定义页面", "页面"],
170
+ content: ["正文", "内容"],
171
+ class: ["字典分类", "分类", "类别"],
172
+ environment: ["环境", "配置引导", "环境配置"],
173
+ coverage: ["覆盖率", "覆盖清单", "覆盖面"],
174
+ perm: ["数据权限", "权限组", "权限"],
175
+ artifact: ["产物"],
176
+ request: ["异步请求"],
177
+ node: ["节点"],
178
+ instance: ["实例"],
179
+ button: ["按钮", "操作按钮"],
180
+ });
181
+ const DESTRUCTIVE_RE = /delete|remove|purge/i;
182
+ export function toolSearchMeta(tool) {
183
+ const segments = tool.name.split(".");
184
+ const last = segments[segments.length - 1];
185
+ const objectPath = segments.slice(0, -1);
186
+ const action = ACTION_VERBS[last];
187
+ const tier = segments.length === 1 ? "manual" : action === undefined ? "partial" : "derived";
188
+ return {
189
+ name: tool.name,
190
+ objectPath,
191
+ ...(action === undefined ? {} : { action }),
192
+ tier,
193
+ readOnly: tool.kind === "read",
194
+ destructive: DESTRUCTIVE_RE.test(tool.name),
195
+ };
196
+ }
197
+ /** `--meta`:三档分布 + partial/manual 名单(Step 1 的人工校验清单)。 */
198
+ export function toolSearchMetaReport(registry) {
199
+ const derived = [], partial = [], manual = [];
200
+ for (const tool of registry) {
201
+ const meta = toolSearchMeta(tool);
202
+ if (meta.tier === "derived")
203
+ derived.push(meta.name);
204
+ else if (meta.tier === "partial")
205
+ partial.push(meta.name);
206
+ else
207
+ manual.push(meta.name);
208
+ }
209
+ return { derived, partial, manual };
210
+ }
211
+ /* ────────────────────────────────────────────────────────────────────────────
212
+ * 人工标注层(v3 §三:derived 自动 / partial 补对象 / manual 全手写)。
213
+ * 只登记「名字派生不出来」的信息;别名一律是业务原话,匹配方向 = 查询包含短语。
214
+ * ──────────────────────────────────────────────────────────────────────────── */
215
+ /**
216
+ * 次要对象(parent):句子里出现「模型 + 字段」时,字段类工具再 +WEIGHTS.parent。
217
+ * 定义 = 与本工具相关、但不在本工具对象段里的那个对象。
218
+ */
219
+ const TOOL_PARENTS = Object.freeze({
220
+ "field.create": ["model"], "field.update": ["model"], "field.delete": ["model"], "field.list": ["model"], "field.publish": ["model"],
221
+ "form.publish": ["model"], "form.get": ["model"], "form.draft": ["model"],
222
+ "listview.configure": ["model"], "listview.create": ["model"], "listview.get": ["model"], "listview.list": ["model"], "listview.delete": ["model"],
223
+ "datarule.create": ["model", "field"], "datarule.update": ["model", "field"], "datarule.list": ["model", "field"], "datarule.delete": ["model", "field"],
224
+ "method.create": ["service"], "method.update": ["service"], "method.get": ["service"], "method.delete": ["service"], "method.test": ["service"],
225
+ "org.role.addUsers": ["user"], "org.role.removeUsers": ["user"],
226
+ });
227
+ /** 反向约束:句子里出现这些词时,该工具**直接出局**(它不是干这个的)。见 scoreTools 内的一票否决注释。 */
228
+ const TOOL_CONSTRAINTS = Object.freeze({
229
+ // 校验语义归 datarule(round10 回归的检索面版本):「给金额字段加校验」不能把
230
+ // field.create 排前面;嵌套子表平台不支持,不伪造入口。
231
+ "field.create": ["校验", "嵌套子表", "子表套子表"],
232
+ });
233
+ /**
234
+ * 检索面的别名出口(r59 M1-1):别名已迁到各工具的 `defineTool({ search })`。
235
+ *
236
+ * 保留这个函数是为了「按名字取别名」的少数调用方(评测脚本、校验门)不必知道
237
+ * `ToolDefinition` 的形状;它不做任何派生,避免与 `toolSearchFacets` 漂移。
238
+ */
239
+ export function toolAliasesOf(registry, name) {
240
+ return registry.find((tool) => tool.name === name)?.search?.intents ?? [];
241
+ }
242
+ /* ────────────────────────────────────────────────────────────────────────────
243
+ * 打分(v3 §二):全量召回、多信号加权、capability 只做 prior。
244
+ * 权重集中在一处,评测(run-search-eval.ts)驱动调参。
245
+ * ──────────────────────────────────────────────────────────────────────────── */
246
+ export const SEARCH_WEIGHTS = Object.freeze({
247
+ exactName: 100,
248
+ nameContains: 40,
249
+ actionObjectPair: 24,
250
+ // 评测驱动(run-search-eval N08/N13/N21):作者短语必须压过机械的动作+对象对
251
+ // ——「注册接口给业务规则用」的 pair 落在 rule.save(注册·业务规则)上,
252
+ // 「给角色加用户」落在 org.role.create(加·角色)上,都是错工具。
253
+ toolAlias: 55,
254
+ recipe: 20,
255
+ intentAlign: 18,
256
+ parentObject: 15,
257
+ objectMatch: 12, // 命中「容器段」(service.category.* 里的 service)时减半,见 objectWeight
258
+ // M1-2a(族 A):同分裁决。命中多个对象段(dictionary.**class**.delete = 2 段)
259
+ // 或命中更长的词典词(「角色组」3 字 > 「角色」2 字)都是「更特指」的证据,
260
+ // 原来这些信息完全不参与打分,同分一律退化成名字序(B03/W04/W05/W07 的根因)。
261
+ objectSpecificity: 5,
262
+ // M1-2a:动作段命中(「挪到」→ `move` 段、「勾选」→ `setButtons` 段)。意图类把
263
+ // 「怎么改」抹平了(rule.disable 与 rule.node.update 都是 update),这里按段补。
264
+ actionSegmentMatch: 20,
265
+ // M1-2d:查询要清单时,动作段是 list 的工具压过 get。
266
+ collectionIntent: 8,
267
+ description: 8,
268
+ capabilityPrior: 6,
269
+ constraint: -50, // 语义上是一票否决(见 scoreTools 内注释),保留数值仅为文档
270
+ destructiveMismatch: -30,
271
+ // 评审 P0-1:「查 field.delete」里 exactName(+100)+对象(+12) 叠出 112,-30 压不住,
272
+ // destructive 照样置顶。读意图且无删除意图时直接压穿任何正信号(净分≤0 即出局)。
273
+ destructiveReadIntent: -120,
274
+ });
275
+ /** top1−top2 分差小于该值 → `filtered.ambiguous = true`(返回 top 让 agent 自己挑)。 */
276
+ export const SEARCH_MARGIN_THRESHOLD = 10;
277
+ function norm(text) {
278
+ return text.toLowerCase().replace(/[._\s-]/g, "");
279
+ }
280
+ /**
281
+ * 否定子句(v3 评测集 G 组):「不要新建服务,只给已有服务加方法」里,短语类
282
+ * 信号(别名/对象/意图/父对象/能力场景)只允许从**非否定子句**取词。全部子句
283
+ * 都被否定时按空处理(通常会落到诚实的零命中 + 能力候选)。
284
+ */
285
+ const NEGATION_HEAD = /^(不|别|无需|请勿|莫)/;
286
+ /**
287
+ * 否定标记也出现在子句中部(评审 P1-3):「请**不要**新建服务」「我**不想**删除」
288
+ * 「**先别**创建模型」。子句**开头**的 不/别/无需/请勿/莫 一律否定(覆盖 不改/不建/
289
+ * 不删/不想……);中部按整词收,**刻意不收裸「别」**——「调用别人家的接口」里的
290
+ * 「别」不是否定,收了会把合法查询整句作废。
291
+ */
292
+ const NEGATION_MARKS = ["不要", "不用", "无需", "先别", "先不", "不想", "不希望", "不打算", "请勿", "别删", "别建", "别改", "别加"];
293
+ function positiveText(query) {
294
+ const clauses = query.split(/[,,。;;!!??、]/).map((c) => c.trim()).filter(Boolean);
295
+ const positive = clauses.filter((c) => !NEGATION_HEAD.test(c) && !NEGATION_MARKS.some((mark) => c.includes(mark)));
296
+ return positive.join("");
297
+ }
298
+ export function scoreTools(registry, query) {
299
+ const rawQuery = query.trim();
300
+ const nq = norm(rawQuery);
301
+ if (nq.length === 0)
302
+ return [];
303
+ const posText = positiveText(rawQuery);
304
+ const nqPos = norm(posText);
305
+ // 意图词收集(否定子句里的意图词一并作废——「别删数据」不给 delete 意图)。
306
+ const intents = new Set();
307
+ const weakIntents = new Set();
308
+ if (posText.length > 0) {
309
+ for (const { word, cls, weak } of INTENT_WORDS) {
310
+ if (!posText.includes(word))
311
+ continue;
312
+ if (weak)
313
+ weakIntents.add(cls);
314
+ else
315
+ intents.add(cls);
316
+ intents.add(cls);
317
+ }
318
+ }
319
+ const strongIntents = new Set();
320
+ if (posText.length > 0) {
321
+ for (const { word, cls, weak } of INTENT_WORDS)
322
+ if (!weak && posText.includes(word))
323
+ strongIntents.add(cls);
324
+ }
325
+ // 对象词反查:哪个英文对象段被查询点名(中文同义词或英文段本身)。
326
+ // 同时记录「命中的词典词有多长」——长词是更特指的证据(M1-2a)。
327
+ const wantedObjects = new Set();
328
+ const objectWordBySeg = new Map();
329
+ if (posText.length > 0) {
330
+ for (const [segment, words] of Object.entries(OBJECT_LEXICON)) {
331
+ // 长词优先:同一段里「角色组」与「角色」都命中时取更长的那个,否则
332
+ // objectPath 的最末段判定会把 roleGroup 误算成 role(W07)。
333
+ const hitWords = words.filter((word) => posText.includes(word) || nqPos.includes(segment));
334
+ if (hitWords.length === 0)
335
+ continue;
336
+ wantedObjects.add(segment);
337
+ objectWordBySeg.set(segment, hitWords.reduce((longest, word) => (word.length > longest.length ? word : longest), hitWords[0]));
338
+ }
339
+ }
340
+ // 长词覆盖短词(M1 泛化):同一段文字里「应用**树**」是 folder 的词,不该同时
341
+ // 算 app 的「应用」;「角色**组**」同理。做法:短词的出现区间完全落在某个更长
342
+ // 命中词的区间内时,把短词所在段从 wantedObjects 里剔除。
343
+ if (posText.length > 0) {
344
+ const spans = [];
345
+ for (const [segment, word] of objectWordBySeg) {
346
+ const start = posText.indexOf(word);
347
+ if (start >= 0)
348
+ spans.push({ segment, word, start });
349
+ }
350
+ for (const short of spans) {
351
+ const shadowed = spans.some((long) => long !== short
352
+ && long.word.length > short.word.length
353
+ && long.start <= short.start
354
+ && long.start + long.word.length >= short.start + short.word.length);
355
+ if (shadowed) {
356
+ wantedObjects.delete(short.segment);
357
+ objectWordBySeg.delete(short.segment);
358
+ }
359
+ }
360
+ }
361
+ const readIntents = [...intents];
362
+ const queryWantsCollection = posText.length > 0
363
+ && COLLECTION_WORDS.some((word) => posText.includes(word))
364
+ && readIntents.includes("read")
365
+ && !readIntents.some((cls) => cls === "create" || cls === "update" || cls === "delete")
366
+ && !SINGULAR_MARKERS.some((word) => posText.includes(word));
367
+ // 读主句:句首是读动词 → 写意图一律降噪(见 READ_LEADING_VERBS 注释)。
368
+ const readPrimary = READ_LEADING_VERBS.some((verb) => posText.trimStart().startsWith(verb))
369
+ || (strongIntents.has("read") && !strongIntents.has("create") && !strongIntents.has("update") && !strongIntents.has("delete"));
370
+ // 句中是否出现**段级动作词**(「勾选」「撤销权限」「改个名字」「挪到」…)。
371
+ // 出现时 (动作类, 对象) 这个粗粒度二元组不再区分候选(rule.disable 与
372
+ // rule.node.update 都是 update·rule),一并以更细的信号裁决——否则 35 分的
373
+ // 二元组会压过 20 分的精确动作词(W12/W13/W14/B03/B11/B13 的同一根因)。
374
+ const queryHasSpecificAction = Object.values(ACTION_SEGMENT_LEXICON).some((words) => words.some((word) => containsLoose(posText, word)));
375
+ // 最长别名优先:当「查字典」与「查字典引用」同时是(不同工具的)命中别名时,
376
+ // 短语是真子串的那个作废——否则 dictionary.list 会抢走 dictionary.references
377
+ // 的「查字典引用」(评测 N16)。别名本身仍是查询包含短语,方向不变。
378
+ const matchedAliasPhrases = new Set();
379
+ if (posText.length > 0) {
380
+ // 别名现在住在各工具的 `search.intents`(M1-1 迁移),这里从注册表收集,
381
+ // 与 `toolSearchFacets` 同一来源——不再有第二份中央表。
382
+ for (const tool of registry) {
383
+ for (const alias of tool.search?.intents ?? []) {
384
+ if (alias.length >= 2 && (posText.includes(alias) || nqPos === norm(alias)))
385
+ matchedAliasPhrases.add(alias);
386
+ }
387
+ }
388
+ }
389
+ // 别名归属(M1-2a):只有「更长的命中短语属于**别的工具**」时才作废。
390
+ // 同一工具内部的长短短语不该互相取消——dictionary.usage 的「使用标记」曾被自己的
391
+ // 「设置使用标记」取消掉,结果被 dictionary.records 抢走(X10)。
392
+ const aliasOwners = new Map();
393
+ for (const tool of registry) {
394
+ for (const alias of tool.search?.intents ?? [])
395
+ aliasOwners.set(alias, [...(aliasOwners.get(alias) ?? []), tool.name]);
396
+ }
397
+ const effectiveAlias = (alias, toolName) => {
398
+ if (!matchedAliasPhrases.has(alias))
399
+ return false;
400
+ for (const other of matchedAliasPhrases) {
401
+ if (other === alias || !other.includes(alias))
402
+ continue;
403
+ const owners = aliasOwners.get(other) ?? [];
404
+ if (owners.length > 0 && !owners.includes(toolName))
405
+ return false;
406
+ }
407
+ return true;
408
+ };
409
+ const routeByLane = capabilityRouteIndexSafe(registry);
410
+ const hits = [];
411
+ for (const tool of registry) {
412
+ const meta = toolSearchMeta(tool);
413
+ const normalizedName = norm(tool.name);
414
+ const signals = [];
415
+ // ① 名称类(最强):完全相等,或整段工具名出现在查询里(「rule.save 保存规则」)。
416
+ const exact = nq === normalizedName || (normalizedName.length >= 4 && nq.includes(normalizedName));
417
+ if (exact)
418
+ signals.push({ key: "exactName", weight: SEARCH_WEIGHTS.exactName, via: `工具名 "${tool.name}"` });
419
+ else if (nq.length >= 2 && normalizedName.includes(nq)) {
420
+ signals.push({ key: "nameContains", weight: SEARCH_WEIGHTS.nameContains, via: `工具名含 "${rawQuery}"` });
421
+ }
422
+ // ② 别名(业务原话,只在非否定子句里找)。
423
+ let aliasHit = false;
424
+ // 长词优先:短别名可能被「后面紧跟别的对象词」判为越界,但同一工具更长的别名
425
+ // 才是真正该命中的那条(「查看服务列表」不该被「查看服务」的越界检查连坐——N25)。
426
+ const toolIntents = [...(tool.search?.intents ?? [])].sort((left, right) => right.length - left.length);
427
+ for (const alias of toolIntents) {
428
+ if (!effectiveAlias(alias, tool.name))
429
+ continue;
430
+ // 安全规则(B20/HW08):用户要**删**,而本工具不是破坏性工具 → 别名不生效
431
+ // (「删除字段校验规则」不该被 datarule.create 的「字段校验」顶到第一)。
432
+ if (intents.has("delete") && !meta.destructive)
433
+ continue;
434
+ // M1-2a/W04:别名后**紧跟**的另一个对象词不归本工具时,别名整条作废
435
+ //(不是扣分)——「新建字典分类」里「新建字典」命中 dictionary.save,但
436
+ // 紧随的「分类」只属于 dictionary.class.*;分数微调压不住 +40 的别名。
437
+ const aliasEnd = posText.indexOf(alias) + alias.length;
438
+ const nextChar = posText.slice(aliasEnd, aliasEnd + 1);
439
+ const others = [...objectWordBySeg].filter(([segment]) => !meta.objectPath.includes(segment));
440
+ const yields = others.some(([, word]) => posText.startsWith(word, aliasEnd))
441
+ // 「列出模型**里**的**字段**」:容器标记之后**还有别的对象词**,别名只管到容器
442
+ // 为止。只看到「的/里」就作废会把「看规则跑过没有**的**日志」误伤(HX04)——
443
+ // 那里的「日志」不是独立对象词,别名本身才是对的答案。
444
+ || (["里", "下", "中", "内", "的"].includes(nextChar)
445
+ && others.some(([, word]) => posText.indexOf(word, aliasEnd + 1) >= 0));
446
+ if (yields)
447
+ break;
448
+ signals.push({ key: "toolAlias", weight: SEARCH_WEIGHTS.toolAlias, via: `别名「${alias}」` });
449
+ aliasHit = true;
450
+ break;
451
+ }
452
+ // ③ 配方(id 正向 / 标题与别名短语)。
453
+ for (const recipe of tool.executionMetadata?.recipes ?? []) {
454
+ const idHit = nq.length >= 2 && norm(recipe.id).includes(nq);
455
+ const titleHit = recipe.title.length >= 2 && (posText.includes(recipe.title) || nqPos === norm(recipe.title));
456
+ const aliasHitRecipe = (recipe.aliases ?? []).some((a) => (a.length >= 2 && posText.includes(a)) || nqPos === norm(a));
457
+ if (idHit || titleHit || aliasHitRecipe) {
458
+ signals.push({ key: "recipe", weight: SEARCH_WEIGHTS.recipe, via: `配方「${titleHit ? recipe.title : recipe.id}」` });
459
+ break;
460
+ }
461
+ }
462
+ // ④ 对象段命中(加分项,不是门槛——v3 对 v2 P0-1 的回答)。命中**最末段**
463
+ //(service.dbconnpool.list 的 dbconnpool)给全分;只命中容器段
464
+ //(service.category.list 的 service)减半——「看服务」的 top1 曾因此
465
+ // 落到 service.category.list 上(评测 R05)。
466
+ //
467
+ // M1-2a(族 A):命中**多个**对象段或命中**更长的词典词**时追加特指度分。
468
+ // 原来只取「第一个命中的段」、且完全不比较词长,于是
469
+ // 「新建字典分类」→ dictionary.save(只中 dictionary)
470
+ // 「新建一个角色组」→ org.role.create(「角色组」被「角色」切断)
471
+ // 这类同分全部退化成名字序。
472
+ const matchedSegments = meta.objectPath.filter((segment) => wantedObjects.has(segment));
473
+ const objectSeg = matchedSegments[0];
474
+ const objectHit = objectSeg !== undefined;
475
+ const lastSegment = meta.objectPath[meta.objectPath.length - 1];
476
+ // 容器词识别(M1-2a):对象词紧跟「里/下/中/的」时是**容器**
477
+ //(「这个应用**里**有哪些模型」里的「应用」),真正的重心是后面的名词。
478
+ // 原来两者同权,于是 app.list 压过 model.list(B01/B05/B21/B30 的同一根因)。
479
+ const isContainerWord = (segment) => {
480
+ if (segment === undefined)
481
+ return false;
482
+ const word = objectWordBySeg.get(segment);
483
+ if (word === undefined)
484
+ return false;
485
+ const at = posText.indexOf(word);
486
+ if (at < 0)
487
+ return false;
488
+ const after = posText.slice(at + word.length, at + word.length + 1);
489
+ return after === "里" || after === "下" || after === "中" || after === "的" || after === "内";
490
+ };
491
+ const localLongestWord = matchedSegments.reduce((longest, segment) => {
492
+ const word = objectWordBySeg.get(segment) ?? "";
493
+ return word.length > longest ? word.length : longest;
494
+ }, 0);
495
+ const lastMatched = matchedSegments.includes(lastSegment);
496
+ const objectWeight = objectHit
497
+ ? (lastMatched && !isContainerWord(lastSegment) ? SEARCH_WEIGHTS.objectMatch : SEARCH_WEIGHTS.objectMatch / 2)
498
+ : 0;
499
+ if (objectHit)
500
+ signals.push({ key: "objectMatch", weight: objectWeight, via: `对象「${objectWordBySeg.get(objectSeg)}」` });
501
+ if (matchedSegments.length > 1) {
502
+ // 每多命中一段 +specificity:`dictionary.class.delete` 两段 vs `dictionary.save` 一段。
503
+ const bonus = SEARCH_WEIGHTS.objectSpecificity * (matchedSegments.length - 1);
504
+ signals.push({ key: "objectSpecificity", weight: bonus, via: `同时点名「${matchedSegments.map((s) => objectWordBySeg.get(s)).join("·")}」` });
505
+ }
506
+ else if (objectHit && localLongestWord > 2) {
507
+ // 同一段但命中的是长词(「角色组」vs「角色」):长词 3 字起每多一字 +specificity/2 取整。
508
+ // 按**本工具命中的段**取最长词——否则 org.role.create 也享受「角色组」的 3 字奖励(W07)。
509
+ const bonus = Math.round((SEARCH_WEIGHTS.objectSpecificity * (localLongestWord - 2)) / 2);
510
+ if (bonus > 0)
511
+ signals.push({ key: "objectSpecificity", weight: bonus, via: `特指「${objectWordBySeg.get(objectSeg)}」` });
512
+ }
513
+ // ④b 动作段命中(M1-2a):按**名字的动作段本身**匹配中文动作词,
514
+ // 区分「改名」(update 段)与「挪到」(move 段)这类被意图类抹平的差别。
515
+ const actionSegmentName = meta.objectPath.length === 0 ? tool.name : (tool.name.split(".").pop() ?? "");
516
+ for (const word of ACTION_SEGMENT_LEXICON[actionSegmentName] ?? []) {
517
+ if (containsLoose(posText, word)) {
518
+ // 词越长越特指(「写页面正文」6 字 > 「发布」2 字)。
519
+ const weight = Math.min(30, SEARCH_WEIGHTS.actionSegmentMatch + 3 * (word.length - 2));
520
+ signals.push({ key: "actionSegmentMatch", weight, via: `动作「${word}」` });
521
+ // 动作词与句首对齐 = 这就是该句的谓语(「**停用**字典…记录」vs「字典记录」)。
522
+ // 同分时用它裁决,避免退化成名字序(W06/W13/W14)。
523
+ if (posText.trimStart().startsWith(word.slice(0, 1))) {
524
+ signals.push({ key: "actionLead", weight: 3, via: `谓语「${word}」` });
525
+ }
526
+ break;
527
+ }
528
+ }
529
+ // ⑤ 动作+对象成对(derived 档才有动作类;upsert 与 create/update 双向兼容)。
530
+ const aligns = (action, intent) => {
531
+ if (action === undefined)
532
+ return false;
533
+ if (action === "upsert")
534
+ return intent === "upsert" || intent === "create" || intent === "update";
535
+ if (intent === "upsert")
536
+ return action === "create" || action === "update";
537
+ return action === intent;
538
+ };
539
+ let intentWord = "";
540
+ for (const { word, cls } of INTENT_WORDS)
541
+ if (posText.includes(word) && aligns(meta.action, cls)) {
542
+ intentWord = word;
543
+ break;
544
+ }
545
+ if (objectHit && meta.action !== undefined && intentWord !== "" && !queryHasSpecificAction && !aliasHit) {
546
+ signals.push({ key: "actionObjectPair", weight: SEARCH_WEIGHTS.actionObjectPair, via: `动作+对象「${intentWord}·${objectWordBySeg.get(objectSeg)}」` });
547
+ }
548
+ // ⑥ 意图对齐(读/删的安全信号主体)。必须先有确定性信号(名称/别名/对象/配方),
549
+ // 否则裸「查」「发布」会把全量只读工具拖进来(v2 P0-1 的另一个面)。
550
+ const anchored = exact || aliasHit || objectHit || signals.some((s) => s.key === "nameContains" || s.key === "recipe");
551
+ const effectiveRead = meta.action === "read" || (meta.action === undefined && meta.readOnly);
552
+ // 读主句时只认读意图:写意图(「发布」这类名词短语里的动词)不给分。
553
+ const writeIntentLive = !readPrimary;
554
+ if (anchored && intents.size > 0) {
555
+ if (intents.has("read") && effectiveRead)
556
+ signals.push({ key: "intentAlign", weight: SEARCH_WEIGHTS.intentAlign, via: "只读意图" });
557
+ if (intents.has("delete") && meta.destructive)
558
+ signals.push({ key: "intentAlign", weight: SEARCH_WEIGHTS.intentAlign, via: "删除意图" });
559
+ const writeMatches = (intents.has("create") && (meta.action === "create" || meta.action === "upsert"))
560
+ || (intents.has("update") && (meta.action === "update" || meta.action === "upsert"));
561
+ if (writeIntentLive && writeMatches) {
562
+ // 弱意图(配置/发布/保存…)只给一半分:它们是名词时不该压过读意图。
563
+ const weak = !strongIntents.has("create") && !strongIntents.has("update");
564
+ signals.push({ key: "intentAlign", weight: weak ? Math.round(SEARCH_WEIGHTS.intentAlign / 2) : SEARCH_WEIGHTS.intentAlign, via: weak ? "写意图(弱)" : "写意图" });
565
+ }
566
+ }
567
+ // ⑥b 集合意图(M1-2d):要清单时 `list` 压过 `get`;同时不想看单条时
568
+ // `get` 不应拿到动作+对象对的分(两者动作类都是 read,二元组区分不了)。
569
+ const actionSegment = tool.name.split(".").pop() ?? "";
570
+ if (anchored && queryWantsCollection) {
571
+ if (actionSegment === "list")
572
+ signals.push({ key: "collectionIntent", weight: SEARCH_WEIGHTS.collectionIntent, via: "要清单" });
573
+ else if (actionSegment === "get" || actionSegment === "load")
574
+ signals.push({ key: "collectionIntent", weight: -Math.round(SEARCH_WEIGHTS.collectionIntent / 2), via: "要清单(单读让位)" });
575
+ }
576
+ // ⑦ 父对象(「给模型加字段」:字段工具看见 model 再加分)。
577
+ if (anchored && TOOL_PARENTS[tool.name]?.some((parent) => wantedObjects.has(parent))) {
578
+ signals.push({ key: "parentObject", weight: SEARCH_WEIGHTS.parentObject, via: `父对象「${objectWordBySeg.get(TOOL_PARENTS[tool.name].find((p) => wantedObjects.has(p))) ?? "相关对象"}」` });
579
+ }
580
+ // ⑧ 摘要兜底(只正向,绝不对 description 反向——r59 评审红线)。
581
+ const description = tool.description ?? "";
582
+ if (nq.length >= 2 && (description.toLowerCase().includes(rawQuery.toLowerCase()) || norm(description).includes(nq))) {
583
+ signals.push({ key: "description", weight: SEARCH_WEIGHTS.description, via: `工具摘要含 "${rawQuery}"` });
584
+ }
585
+ // ⑨ 能力 prior(v1 的能力词面降级为 +6:能纠偏,绝不屏蔽)。
586
+ const capability = tool.lane === undefined ? undefined : routeByLane.get(tool.lane);
587
+ if (capability !== undefined) {
588
+ const prior = capabilityPriorHit(capability, nq, posText, nqPos);
589
+ if (prior !== undefined)
590
+ signals.push({ key: "capabilityPrior", weight: SEARCH_WEIGHTS.capabilityPrior, via: prior });
591
+ }
592
+ // 负向:约束词 / destructive 但查询没有删除意图(安全信号,v2 完全没做)。
593
+ // 约束是**一票否决**而不是 −50:动作+对象+意图对齐能叠到 +65,有限扣分压不住
594
+ // (实测「给金额字段加校验」的 field.create 仍以 15 分进 Top2)。约束表是人工
595
+ // 策展的「这个问法不是这个工具」,是判定不是偏好。
596
+ const constraintHit = (TOOL_CONSTRAINTS[tool.name] ?? []).some((phrase) => posText.includes(phrase));
597
+ if (constraintHit)
598
+ continue;
599
+ if (meta.destructive && !intents.has("delete")) {
600
+ // 评审 P0-1:读意图下的 destructive 一票压穿(净分≤0 → 出局);无意图/写意图只降位。
601
+ const weight = intents.has("read") ? SEARCH_WEIGHTS.destructiveReadIntent : SEARCH_WEIGHTS.destructiveMismatch;
602
+ signals.push({ key: "destructiveMismatch", weight });
603
+ }
604
+ const positives = signals.filter((s) => s.weight > 0);
605
+ if (positives.length === 0)
606
+ continue;
607
+ const score = signals.reduce((sum, s) => sum + s.weight, 0);
608
+ if (score <= 0)
609
+ continue; // 只有 capability(+6) 的 destructive 工具会被 −30 压到排除
610
+ const strongest = signals.filter((s) => s.via !== undefined).sort((a, b) => Math.abs(b.weight) - Math.abs(a.weight))[0];
611
+ hits.push({ name: tool.name, score, via: strongest?.via ?? "", signals: signals.map((s) => s.key) });
612
+ }
613
+ return hits.sort((left, right) => right.score - left.score || right.signals.length - left.signals.length || left.name.localeCompare(right.name));
614
+ }
615
+ /** 能力词面(标题/别名/id/场景短语)命中 → 一句话理由;不命中 → undefined。 */
616
+ function capabilityPriorHit(capability, nq, posText, nqPos) {
617
+ const normalizedTitle = norm(capability.title);
618
+ if (nq.length >= 2 && normalizedTitle.includes(nq))
619
+ return `能力 ${capability.id} 标题`;
620
+ if (posText.length >= 2 && posText.includes(capability.title))
621
+ return `能力 ${capability.id} 标题`;
622
+ for (const alias of capability.aliases) {
623
+ if (alias.length < 2)
624
+ continue;
625
+ if (norm(alias).includes(nq) || nq.length >= 2 && norm(alias).length >= 2 && nqPos.includes(norm(alias)))
626
+ return `能力 ${capability.id} 别名「${alias}」`;
627
+ if (posText.includes(alias))
628
+ return `能力 ${capability.id} 别名「${alias}」`;
629
+ }
630
+ if (nq.length >= 2 && nq.includes(capability.id))
631
+ return `能力 ${capability.id} id`;
632
+ for (const phrase of CAPABILITY_SCENARIOS[capability.id] ?? []) {
633
+ if (phrase.length < 2)
634
+ continue;
635
+ if (posText.includes(phrase))
636
+ return `能力 ${capability.id} 场景「${phrase}」`;
637
+ if (nq.length >= 3 && phrase.includes(nq))
638
+ return `能力 ${capability.id} 场景「${phrase}」`;
639
+ }
640
+ return undefined;
641
+ }
642
+ /* capability-overview 的路由索引(延迟 import 保持模块图干净)。 */
643
+ import { capabilityRouteIndex, CAPABILITY_SCENARIOS } from "./capability-overview.js";
644
+ function capabilityRouteIndexSafe(registry) {
645
+ return capabilityRouteIndex(registry).routeByLane;
646
+ }
647
+ //# sourceMappingURL=tool-search.js.map