argo-search 2.10.0 → 2.10.2

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 (85) hide show
  1. package/README.en.md +50 -10
  2. package/README.es.md +49 -9
  3. package/README.ja.md +50 -10
  4. package/README.ko.md +50 -10
  5. package/README.md +50 -30
  6. package/SKILL.md +11 -10
  7. package/backends/concept_vectors.bin +0 -0
  8. package/backends/engine_concept_vectors.json +3104 -0
  9. package/backends/engine_registry.yaml +2 -2
  10. package/backends/source_types_cn.json +9 -0
  11. package/config.yaml +105 -24
  12. package/docs/ENGINE_CATALOG.md +8 -8
  13. package/docs/RELEASE_NOTES_v2.10.1.md +57 -0
  14. package/docs/RELEASE_NOTES_v2.10.2.md +48 -0
  15. package/engines/_template_http.yaml +2 -0
  16. package/engines/specs/ncpssd.yaml +3 -0
  17. package/engines/specs/sciverse.yaml +1 -0
  18. package/package.json +4 -2
  19. package/packages/dsh-plugin/dsh/diagnostics.js +8 -3
  20. package/packages/dsh-plugin/dsh/index.js +7 -7
  21. package/packages/dsh-plugin/dsh/runner.js +72 -46
  22. package/packages/dsh-plugin/package.json +1 -1
  23. package/packages/dsh-plugin/test/index.test.js +43 -0
  24. package/scripts/argo_engine_registry.py +30 -4
  25. package/scripts/argo_paths.py +7 -1
  26. package/scripts/build_concept_table.py +612 -0
  27. package/scripts/build_route_labels.py +285 -0
  28. package/scripts/caliber_dedupe.py +66 -0
  29. package/scripts/caliber_isolation.py +4 -2
  30. package/scripts/ci_drift_gate.py +47 -24
  31. package/scripts/circuit_breaker.py +25 -3
  32. package/scripts/concept_lookup.py +212 -0
  33. package/scripts/engine_dispatch.py +6 -8
  34. package/scripts/engine_status.py +12 -5
  35. package/scripts/engines.py +29 -7
  36. package/scripts/engines_base.py +48 -17
  37. package/scripts/engines_builders_data.py +10 -3
  38. package/scripts/engines_builders_skill.py +87 -10
  39. package/scripts/evidence.py +26 -5
  40. package/scripts/extend_route_labels.py +239 -0
  41. package/scripts/extend_route_labels_by_capability.py +344 -0
  42. package/scripts/gen_routing_snapshot.py +22 -3
  43. package/scripts/lang_detect.py +12 -3
  44. package/scripts/local_seek.py +66 -14
  45. package/scripts/mcp_transport.py +1 -1
  46. package/scripts/numeric_verify.py +330 -0
  47. package/scripts/plan.py +25 -4
  48. package/scripts/pre-commit +2 -2
  49. package/scripts/rank_signals.py +48 -4
  50. package/scripts/ranking_eval.py +23 -1
  51. package/scripts/regression_p0p1.py +7 -2
  52. package/scripts/release.py +398 -0
  53. package/scripts/route.py +24 -3
  54. package/scripts/route_accuracy_eval.py +191 -0
  55. package/scripts/route_combo.py +32 -1
  56. package/scripts/route_domains.py +258 -5
  57. package/scripts/route_primary.py +101 -0
  58. package/scripts/search.py +5 -2
  59. package/scripts/search_cli.py +111 -7
  60. package/scripts/search_output.py +73 -1
  61. package/scripts/search_pipeline.py +9 -2
  62. package/scripts/search_rank.py +3 -1
  63. package/scripts/serp_guard.py +11 -0
  64. package/scripts/snippet_clean.py +60 -0
  65. package/scripts/social_engines/twitter_engine.py +127 -43
  66. package/scripts/social_engines/xiaohongshu_engine.py +11 -1
  67. package/scripts/tfidf_router.py +52 -2
  68. package/scripts/train.py +15 -0
  69. package/scripts/url_canon.py +2 -1
  70. package/scripts/verify_with.py +124 -0
  71. package/scripts/video_route.py +3 -3
  72. package/sub-skills/local-search/SKILL.md +3 -2
  73. package/sub-skills/local-search/bm25.py +89 -8
  74. package/sub-skills/local-search/config.yaml +12 -0
  75. package/sub-skills/local-search/parse_maps.yaml +8 -0
  76. package/sub-skills/local-search/parsers.py +5 -2
  77. package/sub-skills/local-search/search_v3.py +87 -1
  78. package/sub-skills/local-search/smart_router.py +1 -1
  79. package/sub-skills/local-seek/SKILL.md +6 -5
  80. package/sub-skills/local-seek/scripts/eval_rank.py +1 -1
  81. package/sub-skills/local-seek/scripts/seek.py +171 -40
  82. package/sub-skills/local-seek/scripts/seek_rank.py +191 -11
  83. package/engines/specs/_cisa_kev.yaml +0 -54
  84. package/engines/specs/_osv.yaml +0 -63
  85. package/scripts/image_vision/vision_probe +0 -0
@@ -168,6 +168,28 @@ def _hard_down_blocked(engine_id: str) -> bool:
168
168
  return False
169
169
 
170
170
 
171
+ def _dep_ready(engine_id: str, specs: dict | None = None) -> bool:
172
+ """引擎声明的外部依赖(CLI 工具等)是否就绪。
173
+
174
+ 路由准入此前不查依赖,只查 enabled/熔断/配额/死源/语言,而执行层
175
+ 另有一套(engine_status 的 dep_ready)。两套判据的后果是 primary
176
+ 可以是一个「路由认为可用、执行必然失败」的引擎:实测本机
177
+ xiaohongshu 缺 xhs CLI,路由仍把它放首位,结果由 fallback 悄悄
178
+ 接管,reason 却写着「→ 小红书」。让路由与执行共用同一个依赖判据。
179
+ """
180
+ spec = (specs or {}).get(engine_id)
181
+ if not isinstance(spec, dict):
182
+ return True
183
+ requires = spec.get("requires")
184
+ if not requires:
185
+ return True
186
+ try:
187
+ from engine_requires import requires_status
188
+ return bool(requires_status(spec).get("dep_ready", True))
189
+ except Exception:
190
+ return True
191
+
192
+
171
193
  def is_engine_routable(
172
194
  engine_id: str,
173
195
  *,
@@ -175,12 +197,15 @@ def is_engine_routable(
175
197
  check_breaker: bool = True,
176
198
  check_hard_down: bool = True,
177
199
  check_dead: bool = False,
200
+ check_deps: bool = True,
178
201
  lang: str = "",
179
202
  specs: dict | None = None,
180
203
  ) -> bool:
181
- """单一引擎路由准入谓词:统一收口 enabled / 熔断 / 配额硬耗尽 / 死源地板 / 语言可达。"""
204
+ """单一引擎路由准入谓词:统一收口 enabled / 依赖 / 熔断 / 配额硬耗尽 / 死源 / 语言可达。"""
182
205
  if enabled is not None and engine_id not in enabled:
183
206
  return False
207
+ if check_deps and not _dep_ready(engine_id, specs):
208
+ return False
184
209
  if lang and not lang_allows(engine_id, lang, (specs or {}).get(engine_id)):
185
210
  return False
186
211
  if check_dead and engine_is_dead(engine_id):
@@ -288,6 +313,7 @@ def select_tfidf_best(query: str,
288
313
  semantic_route,
289
314
  min_score: float = 0.12,
290
315
  enabled: set[str] | None = None,
316
+ vetoed: set[str] | None = None,
291
317
  ) -> tuple[str | None, float, list]:
292
318
  """TF-IDF 语义路由选源:返回 (最佳引擎, 分数, 候选表)。
293
319
 
@@ -303,6 +329,9 @@ def select_tfidf_best(query: str,
303
329
  顶到首位——实测 thesportsdb 0.084 仍是「NBA
304
330
  总决赛」类查询的第一候选,注入后撤销 GEC 地板
305
331
  过滤并占 wave-1 竞速首位,白等它的单引擎超时。
332
+ ⑤ 域规则否决(vetoed):域已用 unless 否决过该引擎所属域时,词面分
333
+ 不得复活它——实测「怎么写论文 查重 降重」域判 chinese_general,
334
+ TF-IDF 仍按「论文」高分把 cnii(日文学术)注入首位。
306
335
 
307
336
  semantic_route 由调用方传入:route.py 经模块属性
308
337
  访问解析(测试打桩 patch("route.semantic_route")
@@ -343,6 +372,8 @@ def select_tfidf_best(query: str,
343
372
  if near_miss is None:
344
373
  near_miss = (cand, score)
345
374
  continue
375
+ if vetoed and cand in vetoed:
376
+ continue
346
377
  tfidf_best = cand
347
378
  tfidf_best_score = score
348
379
  break
@@ -169,8 +169,12 @@ def _get_candidate_domain_indices(query: str) -> set[int] | None:
169
169
  return candidates
170
170
 
171
171
 
172
- def _ensure_domain_compiled(domain: dict[str, Any]) -> list[tuple[re.Pattern, re.Pattern | None]]:
173
- """按需编译单个域的触发词与意图正则(扫到哪个域才编译哪个域)。"""
172
+ def _ensure_domain_compiled(domain: dict[str, Any]) -> list[tuple[Any, Any]]:
173
+ """按需编译单个域的触发词与意图正则(扫到哪个域才编译哪个域)。
174
+
175
+ 返回的 matcher 是鸭子类型:`re.Pattern` 或 `_LiteralMatcher`,两者都提供
176
+ `.search(query)`(前者返回 `re.Match`,后者返回 `_LiteralMatch`,均带 `.span()`)。
177
+ """
174
178
  rules = domain.get("_rules")
175
179
  if rules is not None:
176
180
  return rules
@@ -204,9 +208,124 @@ def _compile_domain_patterns(domains: list[dict[str, Any]]) -> list[dict[str, An
204
208
  return compiled
205
209
 
206
210
 
207
- def _try_compile(src: Any) -> re.Pattern | None:
211
+ # 纯字面 alternation 判定:只认「剥掉开头 (?i) 与最外层括号后,由 | 分隔、
212
+ # 每段都是纯字面字符」的 pattern。字符类里出现正则元字符(. * + ? ^ $ \ [ ] ( ) |)
213
+ # 或内联结构一律不认——判定必须保守,判不准就交回 re.compile,宁可少优化。
214
+ _LITERAL_CHAR = re.compile(r"^[\w\u4e00-\u9fff \-/#&:,.'’]+\Z", re.UNICODE)
215
+
216
+
217
+ def _literal_alternatives(src: str) -> tuple[list[str], bool] | None:
218
+ """判定 pattern 是否为纯字面 alternation;是则返回 (词表, 是否忽略大小写)。
219
+
220
+ 等价性:`(?i)(a|b)` 的 `re.search` 与「query 含 a 或 b(忽略大小写)」等价;
221
+ 无 `(?i)` 时与「query 含 a 或 b(区分大小写)」等价。含非 ASCII 拉丁字母
222
+ (é/ß 等)时 `(?i)` 与 `str.lower()` 的 Unicode 规则不完全一致,故退回。
223
+ """
224
+ if not src:
225
+ return None
226
+ s = src
227
+ ignore_case = False
228
+ if s.startswith("(?i)"):
229
+ s = s[4:]
230
+ ignore_case = True
231
+ # `(?i)` 只作用于其后的表达式。若顶层还有 `|` 且不是「整体被一对括号
232
+ # 包裹」,flag 作用域只覆盖第一个分支(如 `(?i)foo|bar` 的 bar 区分
233
+ # 大小写),此时按整体忽略大小写处理会误判 → 退回 re.compile。
234
+ wrapped = (s.startswith("(") and s.endswith(")")
235
+ and s.count("(") == 1 and s.count(")") == 1)
236
+ if not wrapped:
237
+ depth = 0
238
+ for ch in s:
239
+ if ch == "(":
240
+ depth += 1
241
+ elif ch == ")":
242
+ depth -= 1
243
+ elif ch == "|" and depth == 0:
244
+ return None
245
+ # 只剥「整体被一对括号包裹」的情形(顶层无其他内容)
246
+ if s.startswith("(") and s.endswith(")") and s.count("(") == 1 and s.count(")") == 1:
247
+ s = s[1:-1]
248
+ parts: list[str] = []
249
+ depth = 0
250
+ cur: list[str] = []
251
+ for ch in s:
252
+ if ch == "(":
253
+ depth += 1
254
+ elif ch == ")":
255
+ depth -= 1
256
+ if ch == "|" and depth == 0:
257
+ parts.append("".join(cur))
258
+ cur = []
259
+ else:
260
+ cur.append(ch)
261
+ parts.append("".join(cur))
262
+ if not parts:
263
+ return None
264
+ words: list[str] = []
265
+ for p in parts:
266
+ if not p or not _LITERAL_CHAR.match(p):
267
+ return None
268
+ if ignore_case:
269
+ if any(ord(c) > 127 and not ("\u4e00" <= c <= "\u9fff") for c in p):
270
+ return None
271
+ p = p.lower()
272
+ words.append(p)
273
+ return words, ignore_case
274
+
275
+
276
+ class _LiteralMatch:
277
+ """`_LiteralMatcher.search` 的返回值:只提供调用方用到的 `.span()`。"""
278
+
279
+ __slots__ = ("_span",)
280
+
281
+ def __init__(self, span: tuple[int, int]):
282
+ self._span = span
283
+
284
+ def span(self) -> tuple[int, int]:
285
+ return self._span
286
+
287
+
288
+ class _LiteralMatcher:
289
+ """纯字面 alternation 的匹配器:子串查找替代 `re.compile` + `re.search`。
290
+
291
+ 为什么值得(2026-11-04 实测):域规则 326 条 pattern 里 134 条是纯字面
292
+ alternation(如 `(?i)(金十|jin10)`、`(?i)(技术社区|程序员社区)`),它们每次
293
+ 冷进程都要付一次 `re.compile`(326 条全量实测 23.8 ms),而子串查找零编译、
294
+ 更快。判定由 `_literal_alternatives` 保守把关,判不准的一律走原正则路径。
295
+ """
296
+
297
+ __slots__ = ("_words", "_ignore_case")
298
+
299
+ def __init__(self, words: list[str], ignore_case: bool):
300
+ self._words = words
301
+ self._ignore_case = ignore_case
302
+
303
+ def search(self, query: str) -> _LiteralMatch | None:
304
+ hay = query.lower() if self._ignore_case else query
305
+ best: tuple[int, int] | None = None
306
+ for w in self._words:
307
+ pos = hay.find(w)
308
+ if pos < 0:
309
+ continue
310
+ # 与 re 的 leftmost 语义一致:取最早出现;同位置取分支顺序在前者
311
+ if best is None or pos < best[0]:
312
+ best = (pos, pos + len(w))
313
+ return _LiteralMatch(best) if best is not None else None
314
+
315
+
316
+ def _try_compile(src: Any) -> Any:
317
+ """编译域规则:纯字面 alternation 走子串匹配,其余走 `re.compile`。
318
+
319
+ 返回值是鸭子类型(均提供 `.search(query)`,返回值带 `.span()`):
320
+ `_LiteralMatcher` 或 `re.Pattern`。写坏的正则仍返回 None 被丢弃,
321
+ 「编译失败静默丢弃」的既有语义不变(纯字面判定本身保证每段都是字面
322
+ 字符,不可能写坏)。
323
+ """
208
324
  if not isinstance(src, str) or not src:
209
325
  return None
326
+ literal = _literal_alternatives(src)
327
+ if literal is not None:
328
+ return _LiteralMatcher(*literal)
210
329
  try:
211
330
  return re.compile(src)
212
331
  except re.error:
@@ -220,10 +339,88 @@ def _pattern_entries(domain: dict[str, Any]) -> list[Any]:
220
339
  return list(patterns) if isinstance(patterns, list) else []
221
340
 
222
341
 
342
+ # 声明式否决宏(2026-10-29,issue #34.1):蛋白/化合物/通用医疗词汇在「市场规模/
343
+ # 销售额/集采/医保」等商业研报语境下不是查生信/化学/临床试验库。把公共商业否决集
344
+ # 抽成命名宏 `@commercial_market`,在 config.yaml 的 unless 字段按需引用,消除多域
345
+ # 重复粘贴并保持 `_split_pattern_entry` 单点展开。
346
+ _UNLESS_MACROS: dict[str, str] = {
347
+ "@commercial_market": (
348
+ r"(?i)(市场规模|市场份额|销售额|营收|市值|融资|财报|竞争格局|集采|医保|报销|"
349
+ r"价格|多少钱|商业化|市场预测|行情|股价|龙头股|概念股|"
350
+ r"market\s+size|market\s+share|sales|revenue|valuation|market\s+forecast|pricing)"
351
+ ),
352
+ # 比较决策/获奖新闻否决集(2026-10-31 评测基线):「…是什么」尾部触发词在
353
+ # cn_encyclopedia 与 fact_check 两处各自存在,把比较题(「A 和 B 的区别/
354
+ # 优劣/怎么选」)与得主类新闻题整类锁进点查域。共用一份否决词,新增守卫域
355
+ # 时在 config.yaml 引用 @compare_or_award,不要复制粘贴展开后的正则。
356
+ "@compare_or_award": (
357
+ r"(?i)(区别|比较|对比|怎么选|哪个好|优劣|利弊|差异|权衡|\bvs\b|得主|获奖)"
358
+ ),
359
+ # 本地/免 key 镜像通道否决集(2026-11-04):`local_*` 六个域是用户**显式
360
+ # 选择**本地化通道的意图(`references/usage.md`:「local_ 前缀是本地化/免 key
361
+ # 镜像通道」),但它们在 config 里排在末尾(idx 92-97),而域匹配先到先得——
362
+ # 于是「本地搜索」「arxiv api」「wikipedia api」「bing news」「百度」全部被
363
+ # 靠前的 catch-all / academic / code_search / news_realtime 截走,那六个域
364
+ # 永远拿不到主位(实测 6/6 失配)。
365
+ #
366
+ # 修法:加 `_channel_intent_gate`(见文件下方),查询含本宏意图词时把
367
+ # local_* 域提到首位。词表与 local_* 六域的 patterns 对齐。
368
+ #
369
+ # **词表只收「带通道语义的写法」,不收裸平台名**:`github repo`、
370
+ # `stackoverflow`、`npm package` 既是通道意图也是普通技术词,收进来会误伤
371
+ # 「github repo 教程 推荐」(实测被误判 local_code)。裸平台名交给各域
372
+ # 自己的 patterns 处理,通道门只认明确的通道修饰语——即「平台名 + 本地/
373
+ # 镜像/免 key」的组合,或「本地 + 平台名」的组合。
374
+ "@local_channel": (
375
+ r"(?i)(本地搜索|local search|零成本|free search|本地新闻|本地中文|"
376
+ r"本地代码|本地学术|本地参考|本地通用|"
377
+ r"arxiv api|semantic scholar|crossref|pubmed|site:arxiv\.org|"
378
+ r"wikipedia api|wiktionary|wikiquote|nominatim|openstreetmap|"
379
+ r"site:baidu|site:sogou|"
380
+ r"(?:github|gitlab|stackoverflow|npm|pip|cargo)\s+(?:repo|package)(?:\s+(?:本地|镜像|免\s?key|local|mirror))|"
381
+ r"(?:本地|镜像)\s+(?:github|gitlab|stackoverflow|npm|pip|cargo))"
382
+ ),
383
+ }
384
+
385
+
223
386
  def _split_pattern_entry(entry: Any) -> tuple[Any, Any]:
224
- """触发词条目的两种形态:字符串,或 `{match, unless}`。"""
387
+ """触发词条目的两种形态:字符串,或 `{match, unless}`(unless 支持 @宏名 展开)。
388
+
389
+ `unless` 可以是:
390
+
391
+ - 字符串正则(原样编译);
392
+ - `@宏名`(整体替换成宏的正则);
393
+ - **列表**:每项是字符串正则或 `@宏名`,展开后用 `|` 拼接成一个正则。
394
+
395
+ 列表形态是 2026-11-04 为「一个触发词要挂多个否决集」加的:academic 的
396
+ 论文条目原有写作技巧否决,又要加本地通道否决,两个都要生效——拼接成
397
+ 一个字符串会让 `(?i)` 的作用域只覆盖前半段(实测宏不展开),而整体
398
+ 替换成宏名又会丢掉原有否决。列表让两类否决各占一项、语义清晰。
399
+ """
225
400
  if isinstance(entry, dict):
226
- return entry.get("match"), entry.get("unless")
401
+ unless = entry.get("unless")
402
+ if isinstance(unless, list):
403
+ parts: list[str] = []
404
+ for item in unless:
405
+ if isinstance(item, str) and item in _UNLESS_MACROS:
406
+ parts.append(_UNLESS_MACROS[item])
407
+ elif isinstance(item, str) and item:
408
+ parts.append(item)
409
+ # 拼接前剥掉后续项开头的 `(?i)`:Python 3.11+ 不允许内联 flag
410
+ # 出现在非开头位置(`(?i)a|(?i)b` 编译失败),而宏与正则都自带
411
+ # `(?i)`,剥掉后语义不变(整条仍由第一个 `(?i)` 控制)。
412
+ if parts:
413
+ merged = parts[0]
414
+ for p in parts[1:]:
415
+ if p.startswith("(?i)"):
416
+ p = p[4:]
417
+ merged += "|" + p
418
+ unless = merged
419
+ else:
420
+ unless = None
421
+ elif isinstance(unless, str) and unless in _UNLESS_MACROS:
422
+ unless = _UNLESS_MACROS[unless]
423
+ return entry.get("match"), unless
227
424
  return entry, None
228
425
 
229
426
 
@@ -399,6 +596,59 @@ def _intent_gate(hits: list[dict[str, Any]], query: str) -> list[dict[str, Any]]
399
596
  return kept
400
597
 
401
598
 
599
+ # ── 阶段 4:显式通道意图门(2026-11-04)──────────────────────────────────────
600
+ #
601
+ # 与 `_intent_gate` 对称但方向相反:那个是「点查域在主题句下让位」,这个是
602
+ # 「泛化域在显式通道意图下让位」。
603
+ #
604
+ # 为什么需要:`local_*` 六个域是用户**显式选择**本地化/免 key 通道的意图
605
+ # (`references/usage.md`:「local_ 前缀是本地化/免 key 镜像通道」),但它们在
606
+ # config 里排在末尾(idx 92-97),而域匹配先到先得——「本地搜索」「arxiv api」
607
+ # 「wikipedia api」「github repo」「bing news」「百度」全部被靠前的泛化域截走,
608
+ # 那六个域永远拿不到主位(实测 6/6 失配)。
609
+ #
610
+ # 为什么不在每个泛化域上加 unless:那是打地鼠——code_search 有四条 pattern
611
+ # 命中同一个查询,逐个加否决总会漏(实测加到第三条仍失配)。而且新增泛化域
612
+ # 时又会漏。门放在匹配层,一次覆盖所有泛化域。
613
+ #
614
+ # 判据:查询含 `@local_channel` 宏的意图词,且命中列表里有 `local_*` 域时,
615
+ # 把非 local_ 的命中域降级为次域(保留在列表里,不删除——它们仍可能补位)。
616
+
617
+ _CHANNEL_INTENT_RE: re.Pattern | None = None
618
+
619
+
620
+ def _channel_intent_re() -> re.Pattern | None:
621
+ """惰性编译通道意图正则(复用 @local_channel 宏,避免词表两处维护)。"""
622
+ global _CHANNEL_INTENT_RE
623
+ if _CHANNEL_INTENT_RE is None:
624
+ src = _UNLESS_MACROS.get("@local_channel")
625
+ if not src:
626
+ return None
627
+ try:
628
+ _CHANNEL_INTENT_RE = re.compile(src, re.I)
629
+ except re.error:
630
+ return None
631
+ return _CHANNEL_INTENT_RE
632
+
633
+
634
+ def _channel_intent_gate(hits: list[dict[str, Any]], query: str) -> list[dict[str, Any]]:
635
+ """显式通道意图存在时,把 local_* 域提到首位(泛化域降为次域)。
636
+
637
+ 不删除泛化域——它们仍可能在 local 通道不可用时补位(fallback 语义)。
638
+ 只调整顺序:主域是 local_*,泛化域退到次域位置。
639
+ """
640
+ if not hits:
641
+ return hits
642
+ re_ = _channel_intent_re()
643
+ if re_ is None or re_.search(query) is None:
644
+ return hits
645
+ local_hits = [h for h in hits if str(h.get("name", "")).startswith("local_")]
646
+ if not local_hits:
647
+ return hits # 没有 local 域命中:不调整(说明 local 域规则没覆盖)
648
+ others = [h for h in hits if not str(h.get("name", "")).startswith("local_")]
649
+ return local_hits + others
650
+
651
+
402
652
  # ── 对外入口 ──────────────────────────────────────────────────────────────────
403
653
 
404
654
  def match_domains(query: str, domains: list[dict[str, Any]] | None = None,
@@ -453,6 +703,9 @@ def match_domains(query: str, domains: list[dict[str, Any]] | None = None,
453
703
 
454
704
  hits = _social_domain_first(hits)
455
705
  hits = _intent_gate(hits, query)
706
+ # 显式通道意图门放在最后:它只重排已命中列表(local_* 提前),不改变
707
+ # 「哪些域命中」这个事实,因此不影响前面的意图门与社交提前逻辑。
708
+ hits = _channel_intent_gate(hits, query)
456
709
  hits = hits[:max_n]
457
710
  return hits if hits else ([catch_all] if catch_all else [])
458
711
 
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env python3
2
+ """route_primary.py — primary 可执行性顺位与域否决查询。
3
+
4
+ ## 为什么单独成模块
5
+
6
+ `route.py` 已压着 1000 行硬限,而这两件事都是**独立的判定**,与路由主干的
7
+ 装配流程无关:
8
+
9
+ 1. `promote_executable_primary`:combo 定稿后把 primary 顺位到第一个
10
+ 「路由与执行都判可用」的引擎;
11
+ 2. `domain_vetoed_engines` / `vetoes_apply`:把域规则的 `unless` 否决
12
+ 事实交给 TF-IDF 注入层。
13
+
14
+ 放在这里,route.py 只留两个调用点。
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import Any
20
+
21
+ from config import get_engines
22
+ from route_combo import is_engine_routable
23
+
24
+
25
+ def promote_executable_primary(combo: list[str], specs: dict | None = None,
26
+ enabled: set[str] | None = None
27
+ ) -> tuple[list[str], str | None]:
28
+ """把 primary 顺位到第一个「路由与执行都判可用」的引擎。
29
+
30
+ 路由准入与执行准入此前不是同一套判据:`is_engine_routable` 查
31
+ enabled/依赖/熔断/配额/死源/语言,而执行层的 `engine_status` 另算
32
+ dep_ready——两者在 2026-11-02 才对齐。即便对齐后仍有一个缺口:
33
+ `is_engine_routable` 默认 check_deps=True,但域装配早期
34
+ (_get_engines_combo 与 policy 截断)不看依赖,于是 xiaohongshu 这类缺
35
+ CLI 的引擎能一路占住首位,实际交付由 fallback 接管,reason 却写着
36
+ 「→ 小红书」。
37
+
38
+ 顺位不改写 combo 内容,只把「执行不了」的成员换到后面;全组都不可执行
39
+ 时保持原序(fail-open,由执行层报错而不是路由层静默换源)。
40
+ """
41
+ if not combo:
42
+ return combo, None
43
+ # 必须自己取 specs:route 的 _specs_snapshot() 只读已加载的 engines 模块,
44
+ # 路由路径下它恒为空表,依赖判据会因此对全部引擎失效。
45
+ if specs is None:
46
+ try:
47
+ specs = get_engines()
48
+ except Exception:
49
+ specs = {}
50
+ if is_engine_routable(combo[0], enabled=enabled, specs=specs):
51
+ return combo, None
52
+ for cand in combo[1:]:
53
+ if is_engine_routable(cand, enabled=enabled, specs=specs):
54
+ rest = [e for e in combo if e != cand]
55
+ return [cand] + rest, combo[0]
56
+ return combo, None
57
+
58
+
59
+ def domain_vetoed_engines(query: str,
60
+ domains: list[dict[str, Any]] | None = None) -> set[str]:
61
+ """被域规则显式否决的引擎集合(供 TF-IDF 注入层不再复活)。
62
+
63
+ 域规则与 TF-IDF 选源此前是两条互不知情的路径:域规则用 `unless` 否决了
64
+ 某个意图(例如 academic 的「查重/降重」写作语境),TF-IDF 却可以按词面
65
+ 高分把该域的主源重新注入首位——实测「怎么写论文 查重 降重」域判到
66
+ chinese_general、reason 仍写「[TF-IDF→cnii]」,primary 变成日文学术源。
67
+ 把「否决」这个事实交给注入层,让词面分不能覆盖域规则的语义判断。
68
+
69
+ 判据:某域**本可命中**(match 成立)但因 unless 被否决时,该域声明的
70
+ 引擎即视为被否决。与 match_domains 共用 `_ensure_domain_compiled`。
71
+ """
72
+ if domains is None:
73
+ from route_domains import get_domains as _gd, _get_compiled_domains, \
74
+ _ensure_domain_compiled
75
+ domains = _gd()
76
+ else:
77
+ from route_domains import _get_compiled_domains, _ensure_domain_compiled
78
+ compiled = _get_compiled_domains(domains)
79
+ vetoed: set[str] = set()
80
+ for domain in compiled:
81
+ for match_re, unless_re in _ensure_domain_compiled(domain):
82
+ if unless_re is not None and unless_re.search(query):
83
+ if match_re.search(query):
84
+ vetoed.update(domain.get("engines_combo") or [])
85
+ vetoed.update([domain["primary"]] if domain.get("primary") else [])
86
+ break
87
+ return vetoed
88
+
89
+
90
+ def vetoes_apply(query: str, domains: list[dict[str, Any]] | None = None,
91
+ hard_domain: bool = False) -> bool:
92
+ """本次路由是否处在「域规则已否决」状态。
93
+
94
+ 只有**没有实域命中**时才让否决生效:零实域命中说明所有域要么未匹配、
95
+ 要么被 unless 否决,此时 TF-IDF 注入是唯一能改变主源的力量,必须受
96
+ 域规则约束。一旦已有实域命中,该域自身的引擎选择是声明式的,注入只作
97
+ 辅源,不否决。
98
+ """
99
+ if hard_domain:
100
+ return False
101
+ return bool(domain_vetoed_engines(query, domains))
package/scripts/search.py CHANGED
@@ -571,6 +571,7 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
571
571
  exclude_domains: list[str] | None = None,
572
572
  engine_domain: str | None = None,
573
573
  engine_sub_domain: str | None = None,
574
+ quiet: bool = False,
574
575
  timing: StageTiming | None = None) -> dict[str, Any]:
575
576
  """统一搜索便捷入口。
576
577
 
@@ -640,6 +641,7 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
640
641
  engine=engine if not local_first else "local_search",
641
642
  input_kind=input_kind,
642
643
  context=context,
644
+ timing=timing,
643
645
  )
644
646
  if kind == "known-url" and not force_search:
645
647
  plan_info = build_plan(
@@ -787,7 +789,8 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
787
789
  _local_seek_future = None
788
790
  if include_local:
789
791
  _local_seek_future = _get_local_seek_executor().submit(
790
- _run_local_seek, query, n, warn=_local_seek_explicit)
792
+ _run_local_seek, query, n, warn=_local_seek_explicit,
793
+ echo=not quiet)
791
794
 
792
795
  result = execute_search(
793
796
  query=search_query, decision=decision, max_results=n,
@@ -921,7 +924,7 @@ def super_search(query: str, engine: str = "auto", n: int = 5, explain: bool = F
921
924
  timeout=max(_local_deadline - time.monotonic(), 0))
922
925
  except Exception:
923
926
  return []
924
- return _run_local_seek(q, max_n, search_dir)
927
+ return _run_local_seek(q, max_n, search_dir, echo=not quiet)
925
928
 
926
929
  result = shape_response(_ShapeContext(
927
930
  query=query, kind=kind, tier=tier, envelope=envelope, decision=decision,