argo-search 2.14.0 → 2.15.0

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 (207) hide show
  1. package/AGENTS.md +8 -6
  2. package/README.es.md +56 -824
  3. package/README.ja.md +55 -825
  4. package/README.ko.md +55 -823
  5. package/README.md +128 -868
  6. package/README.zh.md +206 -0
  7. package/SKILL.md +17 -18
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +23 -23
  10. package/backends/concept_vectors.bin +0 -0
  11. package/backends/domain_profiles.json +66 -0
  12. package/backends/engine_concept_vectors.json +1525 -1525
  13. package/backends/engine_registry.yaml +193 -46
  14. package/backends/quota_profiles.json +110 -0
  15. package/bin/argo +30 -17
  16. package/config.yaml +196 -36
  17. package/docs/ADDING_NEW_ENGINE.md +10 -0
  18. package/docs/ARGO_INTRO.md +1 -1
  19. package/docs/CHANGELOG.md +45 -0
  20. package/docs/ENGINE_CATALOG.md +128 -112
  21. package/docs/MCP_SETUP.md +2 -2
  22. package/docs/RELEASE_NOTES_v2.14.0.md +12 -1
  23. package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
  24. package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
  25. package/docs/RELEASING.md +53 -1
  26. package/engines/specs/ai_labs.yaml +89 -0
  27. package/engines/specs/artic.yaml +11 -1
  28. package/engines/specs/bilibili_hot.yaml +11 -1
  29. package/engines/specs/brave.yaml +3 -3
  30. package/engines/specs/cisa_alerts.yaml +40 -0
  31. package/engines/specs/cleveland.yaml +15 -1
  32. package/engines/specs/clinicaltrials.yaml +16 -1
  33. package/engines/specs/cn_ai_news.yaml +10 -8
  34. package/engines/specs/cnii.yaml +15 -4
  35. package/engines/specs/deezer.yaml +12 -1
  36. package/engines/specs/digup.yaml +11 -6
  37. package/engines/specs/doaj.yaml +14 -1
  38. package/engines/specs/douyin_hot.yaml +11 -1
  39. package/engines/specs/dw_news.yaml +4 -2
  40. package/engines/specs/endoflife.yaml +16 -1
  41. package/engines/specs/eng_blogs.yaml +63 -0
  42. package/engines/specs/eu_opendata.yaml +11 -1
  43. package/engines/specs/europeana.yaml +22 -5
  44. package/engines/specs/feed.yaml +62 -0
  45. package/engines/specs/felo.yaml +3 -3
  46. package/engines/specs/figshare.yaml +12 -1
  47. package/engines/specs/firecrawl.yaml +3 -0
  48. package/engines/specs/fourget.yaml +5 -2
  49. package/engines/specs/france24.yaml +6 -4
  50. package/engines/specs/fxtwitter.yaml +29 -6
  51. package/engines/specs/grepapp_mcp.yaml +62 -0
  52. package/engines/specs/guardian_rss.yaml +6 -4
  53. package/engines/specs/hackernews.yaml +17 -2
  54. package/engines/specs/hal.yaml +19 -1
  55. package/engines/specs/hf_datasets.yaml +59 -0
  56. package/engines/specs/hf_papers.yaml +17 -1
  57. package/engines/specs/itotii.yaml +13 -1
  58. package/engines/specs/jikan.yaml +12 -10
  59. package/engines/specs/kaggle.yaml +5 -3
  60. package/engines/specs/lobsters.yaml +41 -0
  61. package/engines/specs/local_seek.yaml +6 -0
  62. package/engines/specs/maven.yaml +61 -0
  63. package/engines/specs/nasa_cmr.yaml +12 -1
  64. package/engines/specs/nuget.yaml +57 -0
  65. package/engines/specs/open_meteo.yaml +1 -1
  66. package/engines/specs/redskill.yaml +2 -0
  67. package/engines/specs/searxng.yaml +4 -2
  68. package/engines/specs/sec_edgar.yaml +8 -3
  69. package/engines/specs/tatoeba.yaml +14 -1
  70. package/engines/specs/tinyfish.yaml +2 -0
  71. package/engines/specs/tinyfish_news.yaml +2 -0
  72. package/engines/specs/tinyfish_paper.yaml +2 -0
  73. package/engines/specs/toutiao_hot.yaml +11 -1
  74. package/engines/specs/train.yaml +3 -0
  75. package/engines/specs/tvmaze.yaml +5 -1
  76. package/engines/specs/twitter.yaml +4 -0
  77. package/engines/specs/unpaywall.yaml +6 -0
  78. package/engines/specs/usda.yaml +14 -1
  79. package/engines/specs/vam.yaml +17 -3
  80. package/engines/specs/weibo_hot.yaml +11 -1
  81. package/engines/specs/wolframalpha.yaml +3 -3
  82. package/engines/specs/xiaohongshu.yaml +2 -0
  83. package/engines/specs/zhihu.yaml +3 -18
  84. package/engines/specs/zhihu_kb.yaml +18 -0
  85. package/engines/specs/zhihu_questions.yaml +19 -0
  86. package/package.json +4 -2
  87. package/packages/dsh-plugin/README.md +9 -14
  88. package/packages/dsh-plugin/dsh/client.js +467 -1024
  89. package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
  90. package/packages/dsh-plugin/dsh/native-tools.mjs +61 -113
  91. package/packages/dsh-plugin/dsh/runner.js +2 -0
  92. package/packages/dsh-plugin/dsh/wide-research.js +1 -1
  93. package/packages/dsh-plugin/package.json +8 -3
  94. package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
  95. package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
  96. package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
  97. package/packages/dsh-plugin/test/size-gate.test.js +2 -9
  98. package/scripts/adaptive.py +7 -1
  99. package/scripts/archive_run.py +112 -53
  100. package/scripts/argo_paths.py +40 -3
  101. package/scripts/badcase_ledger.py +153 -10
  102. package/scripts/build_concept_table.py +112 -55
  103. package/scripts/build_release_assets.sh +43 -15
  104. package/scripts/cache.py +5 -1
  105. package/scripts/caliber_isolation.py +60 -23
  106. package/scripts/circuit_breaker.py +56 -8
  107. package/scripts/cli_io.py +20 -2
  108. package/scripts/config_cache.py +31 -0
  109. package/scripts/daemon.py +146 -51
  110. package/scripts/dormant_ledger.py +239 -0
  111. package/scripts/engine_dispatch.py +3 -3
  112. package/scripts/engine_env.py +182 -1
  113. package/scripts/engine_families.py +50 -7
  114. package/scripts/engine_states.py +9 -51
  115. package/scripts/engine_validate.py +150 -6
  116. package/scripts/engines.py +15 -67
  117. package/scripts/engines_base.py +68 -124
  118. package/scripts/engines_builders.py +0 -51
  119. package/scripts/engines_builders_batch10.py +346 -100
  120. package/scripts/engines_builders_batch11.py +2 -75
  121. package/scripts/engines_builders_batch9.py +15 -228
  122. package/scripts/engines_builders_cn.py +0 -194
  123. package/scripts/engines_builders_feeds.py +203 -35
  124. package/scripts/engines_builders_intl.py +15 -443
  125. package/scripts/engines_builders_pixiv.py +2 -16
  126. package/scripts/engines_builders_science.py +0 -85
  127. package/scripts/engines_builders_search.py +7 -14
  128. package/scripts/engines_builders_tech.py +5 -112
  129. package/scripts/engines_builders_weather.py +236 -0
  130. package/scripts/engines_fields.py +91 -0
  131. package/scripts/engines_http.py +135 -0
  132. package/scripts/engines_mcp.py +383 -0
  133. package/scripts/engines_parsers.py +196 -27
  134. package/scripts/engines_schema_drift.py +260 -0
  135. package/scripts/evidence.py +13 -0
  136. package/scripts/evidence_loop.py +93 -5
  137. package/scripts/fetch_jsrun.py +15 -11
  138. package/scripts/fetch_v3.py +28 -28
  139. package/scripts/fulltext_store.py +42 -1
  140. package/scripts/fxtwitter_api.py +8 -7
  141. package/scripts/gen_engine_catalog.py +4 -4
  142. package/scripts/gen_native_tools.py +2 -1
  143. package/scripts/general_pool.py +15 -4
  144. package/scripts/health_check.py +1 -1
  145. package/scripts/link_source.py +65 -24
  146. package/scripts/local_intent.py +51 -15
  147. package/scripts/local_seek.py +37 -4
  148. package/scripts/local_seek_adapter.py +57 -17
  149. package/scripts/mcp_handlers.py +173 -99
  150. package/scripts/mcp_handlers_surface.py +6 -18
  151. package/scripts/mcp_server.py +1 -1
  152. package/scripts/mcp_tools.py +143 -61
  153. package/scripts/mcp_transport.py +42 -10
  154. package/scripts/min_version_scan.py +7 -3
  155. package/scripts/network_aware.py +7 -13
  156. package/scripts/pre-commit +57 -31
  157. package/scripts/query_understanding.py +30 -6
  158. package/scripts/quota.py +6 -1
  159. package/scripts/rank_signals.py +9 -0
  160. package/scripts/recompute.py +15 -5
  161. package/scripts/recovery.py +21 -15
  162. package/scripts/release.py +29 -32
  163. package/scripts/release_check.py +6 -26
  164. package/scripts/replay_eval.py +2 -2
  165. package/scripts/research_cli.py +40 -0
  166. package/scripts/research_notes.py +368 -0
  167. package/scripts/route.py +32 -70
  168. package/scripts/route_audit.py +259 -0
  169. package/scripts/route_combo.py +10 -4
  170. package/scripts/route_domains.py +150 -23
  171. package/scripts/route_lang.py +20 -7
  172. package/scripts/route_log.py +26 -9
  173. package/scripts/route_policy.py +91 -7
  174. package/scripts/route_telemetry_export.py +199 -0
  175. package/scripts/rrf_classic.py +5 -22
  176. package/scripts/search.py +2 -1
  177. package/scripts/search_attribution.py +33 -10
  178. package/scripts/search_cli.py +44 -7
  179. package/scripts/search_entry.py +5 -1
  180. package/scripts/search_output.py +5 -4
  181. package/scripts/search_pipeline.py +12 -0
  182. package/scripts/search_rank.py +21 -11
  183. package/scripts/secret_guard.py +106 -0
  184. package/scripts/semantic_evidence.py +539 -117
  185. package/scripts/settings_page.py +83 -11
  186. package/scripts/social_engines/xiaohongshu_engine.py +2 -1
  187. package/scripts/social_engines/zhihu_engine.py +251 -43
  188. package/scripts/sogou_weixin_browser.py +5 -6
  189. package/scripts/source_audit.py +77 -0
  190. package/scripts/source_ledger.py +2 -15
  191. package/scripts/source_selection.py +45 -20
  192. package/scripts/straggler_policy.py +1 -2
  193. package/scripts/sync_backends.py +24 -0
  194. package/scripts/tfidf_router.py +23 -11
  195. package/scripts/time_utils.py +54 -1
  196. package/scripts/train.py +68 -2
  197. package/scripts/usage_log.py +26 -1
  198. package/sub-skills/argo-wide-research/SKILL.md +68 -0
  199. package/sub-skills/ego-search/SKILL.md +1 -1
  200. package/sub-skills/local-seek/scripts/seek_fts.py +67 -4
  201. package/README.en.md +0 -826
  202. package/scripts/caliber_dedupe.py +0 -66
  203. package/scripts/engines_builders_batch16.py +0 -186
  204. package/scripts/health_probe.py +0 -253
  205. package/scripts/image_vision/vision_probe +0 -0
  206. package/scripts/social_engines/twitter_engine.py +0 -514
  207. package/scripts/sync_installs.py +0 -29
@@ -12,6 +12,7 @@ from search_rank import filter_results_by_domains
12
12
  from search_types import slot_record as dataclass
13
13
  from snippet_clean import clean_snippet
14
14
  import engine_states # 状态词表唯一真源(2026-11-09 收口)
15
+ from except_sets import OPT_IMPORT, SHAPE_BENIGN # 收窄词汇表(2026-11-13 裸吞收口)
15
16
  from typing import Any
16
17
  from output_transparency import ( # noqa: F401
17
18
  _AGGREGATOR_HOSTS,
@@ -712,7 +713,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
712
713
  result.setdefault("limitations", []).append(
713
714
  f"证据门控本次跳过({type(e).__name__}):fetch_required/"
714
715
  "evidence_loop 不可用,高后果域结论请自行核验")
715
- except Exception:
716
+ except SHAPE_BENIGN:
716
717
  pass
717
718
 
718
719
  # 上游权威等级回填(DeepSeek 0-4):单引擎/对冲路径不走五维精排,
@@ -768,7 +769,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
768
769
  from local_seek import local_seek_last_skipped
769
770
  if local_seek_last_skipped():
770
771
  result["local_seek_skipped"] = True
771
- except Exception:
772
+ except OPT_IMPORT + SHAPE_BENIGN:
772
773
  pass
773
774
  if local_hits:
774
775
  _seen_urls = {r.get("url") for r in (result.get("results") or [])
@@ -848,7 +849,7 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
848
849
  sanitize_results_boundary)
849
850
  sanitize_results_boundary(result.get("results"))
850
851
  result["content_trust"] = CONTENT_TRUST_UNTRUSTED
851
- except Exception:
852
+ except OPT_IMPORT + SHAPE_BENIGN:
852
853
  pass
853
854
  # 搜索期告警(issue #34 第 7 条):--json 下告警不能留在 stderr(调用方
854
855
  # 2>&1 合并会破坏 JSON 解析),统一收进响应的 warnings[] 字段。住在
@@ -858,6 +859,6 @@ def shape_response(ctx: _ShapeContext, result: dict[str, Any]) -> dict[str, Any]
858
859
  warns = [w.strip() for w in drain_search_warnings() if w.strip()]
859
860
  if warns:
860
861
  result.setdefault("warnings", []).extend(warns)
861
- except Exception:
862
+ except OPT_IMPORT + SHAPE_BENIGN:
862
863
  pass
863
864
  return result
@@ -79,6 +79,7 @@ import engine_states
79
79
  from stage_timing import tick as _tick, tock as _tock
80
80
  from time_utils import apply_time_window as _apply_time_window
81
81
  from time_utils import sort_results_by_time as _sort_results
82
+ from time_utils import weather_chronological
82
83
 
83
84
 
84
85
  @dataclass(frozen=True)
@@ -641,6 +642,17 @@ def postprocess(req: _SearchRequest, run: _SearchRun, hooks: Any) -> _SearchRun:
641
642
 
642
643
  if merged:
643
644
  merged = _apply_consensus_and_sort(merged, max_results)
645
+ # 天气结果按时间序收口:当前天气在前,逐日预报升序。放在最终截断
646
+ # 之后,避免五维 rerank 的新颖性把最远一天顶到最前(见函数 docstring)。
647
+ # 显式 `--engine open_meteo` 时 domain 会被置成 general,所以判据同时
648
+ # 看域、引擎列表与结果来源,不能只认 domain。
649
+ _weather_scope = (
650
+ domain == "weather_query"
651
+ or "open_meteo" in (engines or [])
652
+ or (bool(merged) and all(r.get("source") == "open_meteo" for r in merged))
653
+ )
654
+ if _weather_scope:
655
+ merged = weather_chronological(merged)
644
656
 
645
657
  _attach_selection_signals(merged, mode, depth)
646
658
 
@@ -28,6 +28,7 @@ import engine_states # 状态词表唯一真源(2026-11-09 收口)
28
28
 
29
29
  from engine_env import env_flag, get_env
30
30
  from url_canon import canonical_url as _canonical_url_impl
31
+ from except_sets import IO_BENIGN, SHAPE_BENIGN # 收窄词汇表(2026-11-13 裸吞收口)
31
32
 
32
33
  # cache 延迟到首次真正需要相似度时再导入(2026-09-27,方案 B3):顶层 import
33
34
  # 会把 cache.py 连带 sqlite3/shutil/tempfile 整条拉进每次 import search 的
@@ -72,6 +73,7 @@ from rank_signals import ( # noqa: E402,F401
72
73
  score_completeness as _score_completeness,
73
74
  score_relevance as _score_relevance,
74
75
  title_stuffing_penalty as _title_stuffing_penalty,
76
+ upstream_score_boost as _upstream_score_boost,
75
77
  )
76
78
 
77
79
  # 中文/英文混合分词用的正则,延迟编译(首次 _tokens 时建)
@@ -281,8 +283,12 @@ def _content_similarity(a: str, b: str) -> float:
281
283
  if _sim_fn is not None:
282
284
  try:
283
285
  return float(_sim_fn(a, b))
284
- except Exception:
285
- pass # 单条相似度计算失败按「无相似度」处理,回退 Jaccard
286
+ except Exception as e:
287
+ # 单条相似度计算失败按「无相似度」处理,回退 Jaccard;相似度查
288
+ # cache 的 sqlite(OperationalError 不在词汇表),保持宽口径仅可见化。
289
+ import logging
290
+ logging.getLogger("unified_search").debug(
291
+ f"query 相似度计算跳过: {type(e).__name__}")
286
292
  import re as _re
287
293
  sa, sb = set(_re.findall(r"[\u4e00-\u9fff]|[a-zA-Z0-9]+", a.lower())), set(_re.findall(r"[\u4e00-\u9fff]|[a-zA-Z0-9]+", b.lower()))
288
294
  if not sa or not sb:
@@ -339,7 +345,7 @@ def minhash_dedupe(
339
345
  try:
340
346
  thr = float(os.environ.get("ARGO_MINHASH_THRESHOLD", str(threshold)))
341
347
  threshold = max(0.5, min(0.98, thr))
342
- except Exception:
348
+ except SHAPE_BENIGN:
343
349
  pass
344
350
  pool = sorted(
345
351
  results,
@@ -470,7 +476,7 @@ def _note_rerank_failure(breaker, category: str, detail: str) -> None:
470
476
  attribution={"category": category,
471
477
  "reason": "语义精排端点不可用", "detail": detail},
472
478
  )
473
- except Exception:
479
+ except IO_BENIGN + SHAPE_BENIGN:
474
480
  pass
475
481
 
476
482
  def rerank_results(query: str, results: list[dict[str, Any]],
@@ -498,8 +504,13 @@ def rerank_results(query: str, results: list[dict[str, Any]],
498
504
  from quota import get_quota_manager
499
505
  if get_quota_manager().is_remote_exhausted("bocha"):
500
506
  return results, engine_states.RERANK_SKIPPED_QUOTA
501
- except Exception:
502
- pass
507
+ except Exception as e:
508
+ # quota 联动是侧信道:fail-open 是被测契约(test_quota_gate_fails_open
509
+ # _when_quota_unavailable 用 RuntimeError 桩验证),不收窄——except_sets
510
+ # 判定规则看 try 块失败的代价,quota 层可抛任意异常。
511
+ import logging
512
+ logging.getLogger("unified_search").debug(
513
+ f"quota 联动检查跳过(fail-open): {type(e).__name__}")
503
514
 
504
515
  # 端点熔断:先问「还该不该打这一枪」。
505
516
  #
@@ -546,7 +557,7 @@ def rerank_results(query: str, results: list[dict[str, Any]],
546
557
  if breaker is not None:
547
558
  try:
548
559
  breaker.record_success(_RERANK_BREAKER_KEY)
549
- except Exception:
560
+ except IO_BENIGN + SHAPE_BENIGN:
550
561
  pass
551
562
  rerank_results_list = data.get("data", {}).get("results", [])
552
563
  if not rerank_results_list:
@@ -758,10 +769,9 @@ def local_five_dim_rerank(query: str, results: list[dict[str, Any]],
758
769
  # prior——浮点加法顺序与改造前一致,金标对拍才可能零差异。
759
770
  pool = enriched[:]
760
771
  for e in pool:
761
- e["_static4"] = (w["relevance"] * e["relevance"]
762
- + w["authority"] * e["authority"]
763
- + w["freshness"] * e["freshness"]
764
- + w["completeness"] * e["completeness"])
772
+ e["_static4"] = (w["relevance"] * e["relevance"] + w["authority"] * e["authority"]
773
+ + w["freshness"] * e["freshness"] + w["completeness"] * e["completeness"]
774
+ + _upstream_score_boost(e["r"]))
765
775
  # 来源侧惩罚(域级集中 / 跨域同质)作为静态分乘子(≤1)在**贪心之前**
766
776
  # 应用:① 无需事后重排,且惩罚表为空时本行是 ×1.0、浮点上逐位无操作,
767
777
  # 「无惩罚时与旧实现逐位一致」的不变式不被破坏;② K 剪枝上界
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env python3
2
+ """secret_guard.py — 输出流自动脱敏拦截器(防止真实凭据反射/外泄给 Agent 与 LLM)。
3
+
4
+ 第一性原理:
5
+ 任何流向终端、JSON 或 MCP 工具返回的文本/结构化数据,都必须经过
6
+ 脱敏拦截,杜绝三类泄露:
7
+ 1. 已配置的真实凭据(从 os.environ 与 envfile 收集的所有有效 API Key/Token);
8
+ 2. URL 参数中的敏感认证(?key=..., &token=..., &secret=...);
9
+ 3. 通用高熵 API 凭据签名模式(sk-..., tvly-..., ghp_..., Bearer ...)。
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ import re
16
+ from typing import Any
17
+
18
+ # 通用高熵 API Key 签名正则
19
+ _GENERIC_KEY_PATTERNS = [
20
+ # OpenAI / DeepSeek / 通用 sk- 开头
21
+ re.compile(r"\b(sk-[a-zA-Z0-9_\-]{20,})\b"),
22
+ # Tavily tvly- 开头
23
+ re.compile(r"\b(tvly-[a-zA-Z0-9_\-]{20,})\b"),
24
+ # GitHub Token (ghp_, github_pat_)
25
+ re.compile(r"\b(ghp_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9_]{40,})\b"),
26
+ # HTTP Bearer 认证头残留
27
+ re.compile(r"(?i)\bBearer\s+([a-zA-Z0-9_\-\.]{24,})\b"),
28
+ # 典型键值对形式
29
+ re.compile(r"(?i)(?:api_key|access_token|secret_key|api_secret)\s*[:=]\s*['\"]?([a-zA-Z0-9_\-]{24,})['\"]?"),
30
+ ]
31
+
32
+ # URL query 敏感参数脱敏
33
+ _URL_PARAM_PATTERN = re.compile(
34
+ r"([?&](?:api_?key|access_?token|token|key|secret|password|auth)=)[^& \t\r\n\"'>]+",
35
+ re.I,
36
+ )
37
+
38
+ # 避免误杀的非密钥常见词
39
+ _WHITELIST = {
40
+ "undefined", "null", "false", "true", "none", "password", "secret", "bearer",
41
+ "http_proxy", "https_proxy", "all_proxy", "no_proxy",
42
+ }
43
+
44
+
45
+ def get_active_secrets() -> set[str]:
46
+ """收集当前环境中加载的真实有效长密钥字符串集合(去重、过滤短串)。"""
47
+ secrets: set[str] = set()
48
+ # 1. 进程环境变量
49
+ for k, v in os.environ.items():
50
+ if not v or len(v) < 8:
51
+ continue
52
+ k_upper = k.upper()
53
+ if (k_upper.startswith("ARGO_") or
54
+ k_upper.endswith(("_KEY", "_TOKEN", "_SECRET", "_PASSWORD", "_APIKEY")) or
55
+ "API_KEY" in k_upper or "ACCESS_KEY" in k_upper):
56
+ if v.lower() not in _WHITELIST:
57
+ secrets.add(v.strip())
58
+
59
+ # 2. envfile 存储的密钥
60
+ try:
61
+ from engine_env import _envfile_load
62
+ file_env = _envfile_load()
63
+ for _k, v in file_env.items():
64
+ if v and len(v) >= 8 and v.lower() not in _WHITELIST:
65
+ secrets.add(v.strip())
66
+ except Exception:
67
+ pass
68
+
69
+ return secrets
70
+
71
+
72
+ def redact_text(text: str, extra_secrets: set[str] | None = None) -> str:
73
+ """对单段文本执行深度脱敏替换。"""
74
+ if not text or not isinstance(text, str):
75
+ return text
76
+
77
+ out = text
78
+
79
+ # 1. 替换已知真实有效凭据
80
+ active_secrets = get_active_secrets()
81
+ if extra_secrets:
82
+ active_secrets.update(extra_secrets)
83
+
84
+ for sec in sorted(active_secrets, key=len, reverse=True):
85
+ if sec in out:
86
+ out = out.replace(sec, "[REDACTED_API_KEY]")
87
+
88
+ # 2. 替换通用高熵 API Key 签名
89
+ for pat in _GENERIC_KEY_PATTERNS:
90
+ out = pat.sub("[REDACTED_SECRET]", out)
91
+
92
+ # 3. 替换 URL query 参数中的敏感参数
93
+ out = _URL_PARAM_PATTERN.sub(r"\1[REDACTED]", out)
94
+
95
+ return out
96
+
97
+
98
+ def redact_data(data: Any, extra_secrets: set[str] | None = None) -> Any:
99
+ """递归对复杂数据结构(dict / list / str)进行全量脱敏。"""
100
+ if isinstance(data, str):
101
+ return redact_text(data, extra_secrets=extra_secrets)
102
+ if isinstance(data, list):
103
+ return [redact_data(item, extra_secrets=extra_secrets) for item in data]
104
+ if isinstance(data, dict):
105
+ return {k: redact_data(v, extra_secrets=extra_secrets) for k, v in data.items()}
106
+ return data