argo-search 2.14.1 → 2.16.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.
- package/AGENTS.md +8 -6
- package/README.es.md +57 -813
- package/README.ja.md +56 -814
- package/README.ko.md +56 -812
- package/README.md +160 -754
- package/README.zh.md +152 -872
- package/SKILL.md +22 -23
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +23 -23
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +149 -6
- package/backends/engine_concept_vectors.json +1525 -1525
- package/backends/engine_registry.yaml +139 -30
- package/backends/quota_profiles.json +83 -3
- package/bin/argo +33 -17
- package/config.yaml +189 -33
- package/docs/ADDING_NEW_ENGINE.md +10 -0
- package/docs/ARGO_INTRO.md +1 -1
- package/docs/CHANGELOG.md +38 -0
- package/docs/ENGINE_CATALOG.md +102 -89
- package/docs/MCP_SETUP.md +10 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
- package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/ai_labs.yaml +89 -0
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/bilibili_hot.yaml +11 -1
- package/engines/specs/brave.yaml +3 -3
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/cisa_alerts.yaml +40 -0
- package/engines/specs/cn_ai_news.yaml +10 -8
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +4 -2
- package/engines/specs/crt_sh.yaml +1 -1
- package/engines/specs/dblp.yaml +1 -1
- package/engines/specs/devto.yaml +1 -1
- package/engines/specs/digup.yaml +11 -6
- package/engines/specs/docker_hub.yaml +1 -1
- package/engines/specs/douyin_hot.yaml +11 -1
- package/engines/specs/dw_news.yaml +4 -2
- package/engines/specs/eng_blogs.yaml +63 -0
- package/engines/specs/europeana.yaml +3 -4
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/felo.yaml +3 -3
- package/engines/specs/firecrawl.yaml +3 -0
- package/engines/specs/fourget.yaml +5 -2
- package/engines/specs/france24.yaml +6 -4
- package/engines/specs/fxtwitter.yaml +30 -7
- package/engines/specs/gbfs_nyc.yaml +1 -1
- package/engines/specs/gleif.yaml +1 -1
- package/engines/specs/gov_regulations.yaml +1 -1
- package/engines/specs/grepapp_mcp.yaml +62 -0
- package/engines/specs/guardian_rss.yaml +6 -4
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/itotii.yaml +13 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -0
- package/engines/specs/lobsters.yaml +41 -0
- package/engines/specs/local_crossref.yaml +3 -1
- package/engines/specs/local_github.yaml +1 -1
- package/engines/specs/local_npm.yaml +6 -0
- package/engines/specs/local_openstreetmap.yaml +1 -1
- package/engines/specs/local_seek.yaml +6 -0
- package/engines/specs/maven.yaml +1 -1
- package/engines/specs/mdn.yaml +1 -1
- package/engines/specs/musicbrainz.yaml +1 -1
- package/engines/specs/nasa_images.yaml +1 -1
- package/engines/specs/nhtsa_vpic.yaml +6 -3
- package/engines/specs/npm.yaml +1 -1
- package/engines/specs/nuget.yaml +1 -1
- package/engines/specs/nvd.yaml +1 -1
- package/engines/specs/open_meteo.yaml +1 -1
- package/engines/specs/openalex.yaml +4 -2
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/redskill.yaml +2 -0
- package/engines/specs/searxng.yaml +4 -2
- package/engines/specs/sec_edgar.yaml +9 -4
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/tinyfish.yaml +2 -0
- package/engines/specs/tinyfish_news.yaml +2 -0
- package/engines/specs/tinyfish_paper.yaml +2 -0
- package/engines/specs/toutiao_hot.yaml +11 -1
- package/engines/specs/train.yaml +3 -0
- package/engines/specs/twitter.yaml +4 -0
- package/engines/specs/unpaywall.yaml +6 -0
- package/engines/specs/vam.yaml +17 -3
- package/engines/specs/weibo_hot.yaml +11 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/wolframalpha.yaml +3 -3
- package/engines/specs/xiaohongshu.yaml +2 -0
- package/engines/specs/zhihu.yaml +3 -18
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/engines/specs/zhihu_kb.yaml +18 -0
- package/engines/specs/zhihu_questions.yaml +19 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/README.md +9 -14
- package/packages/dsh-plugin/dsh/client.js +481 -1037
- package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
- package/packages/dsh-plugin/dsh/index.js +6 -0
- package/packages/dsh-plugin/dsh/runner.js +3 -1
- package/packages/dsh-plugin/dsh/workbench-client.js +796 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +148 -0
- package/packages/dsh-plugin/dsh/workbench.js +966 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +10 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
- package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
- package/packages/dsh-plugin/test/size-gate.test.js +2 -9
- package/packages/dsh-plugin/test/workbench.test.js +92 -0
- package/scripts/adaptive.py +7 -1
- package/scripts/archive_run.py +112 -53
- package/scripts/argo_paths.py +42 -5
- package/scripts/badcase_ledger.py +117 -9
- package/scripts/build_concept_table.py +112 -55
- package/scripts/cache.py +6 -2
- package/scripts/caliber_isolation.py +60 -23
- package/scripts/circuit_breaker.py +72 -11
- package/scripts/cli_io.py +20 -2
- package/scripts/config_cache.py +44 -1
- package/scripts/daemon.py +151 -51
- package/scripts/dormant_ledger.py +23 -9
- package/scripts/engine_dispatch.py +8 -5
- package/scripts/engine_env.py +191 -1
- package/scripts/engine_families.py +50 -7
- package/scripts/engine_states.py +3 -50
- package/scripts/engine_validate.py +13 -45
- package/scripts/engines.py +15 -31
- package/scripts/engines_base.py +66 -61
- package/scripts/engines_builders.py +0 -15
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch10.py +346 -100
- package/scripts/engines_builders_batch11.py +4 -76
- package/scripts/engines_builders_batch13.py +4 -3
- package/scripts/engines_builders_batch14.py +2 -1
- package/scripts/engines_builders_batch15.py +2 -1
- package/scripts/engines_builders_batch9.py +16 -25
- package/scripts/engines_builders_cn.py +7 -201
- package/scripts/engines_builders_data.py +12 -11
- package/scripts/engines_builders_data_macro.py +5 -4
- package/scripts/engines_builders_dsh.py +2 -1
- package/scripts/engines_builders_feeds.py +76 -11
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +18 -117
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_pixiv.py +2 -16
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_search.py +7 -14
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +8 -17
- package/scripts/engines_builders_weather.py +241 -0
- package/scripts/engines_fields.py +91 -0
- package/scripts/engines_http.py +184 -0
- package/scripts/engines_mcp.py +405 -0
- package/scripts/engines_parsers.py +13 -369
- package/scripts/engines_schema_drift.py +260 -0
- package/scripts/evidence.py +13 -0
- package/scripts/evidence_loop.py +19 -4
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_jsrun.py +15 -11
- package/scripts/fetch_v3.py +79 -120
- package/scripts/fulltext_store.py +42 -1
- package/scripts/fxtwitter_api.py +8 -7
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/general_pool.py +15 -4
- package/scripts/health_check.py +1 -1
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/link_source.py +65 -24
- package/scripts/local_seek_adapter.py +57 -17
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_handlers.py +53 -31
- package/scripts/mcp_handlers_surface.py +6 -18
- package/scripts/mcp_transport.py +10 -5
- package/scripts/min_version_scan.py +7 -3
- package/scripts/network_aware.py +7 -13
- package/scripts/numeric_verify.py +3 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/pre-commit +45 -43
- package/scripts/query_understanding.py +30 -6
- package/scripts/quota.py +36 -30
- package/scripts/rank_signals.py +9 -0
- package/scripts/recompute.py +15 -5
- package/scripts/recovery.py +38 -29
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/release.py +14 -26
- package/scripts/release_check.py +5 -25
- package/scripts/replay_eval.py +2 -2
- package/scripts/research_cli.py +40 -0
- package/scripts/research_notes.py +368 -0
- package/scripts/route.py +40 -70
- package/scripts/route_audit.py +259 -0
- package/scripts/route_combo.py +21 -6
- package/scripts/route_domains.py +150 -23
- package/scripts/route_lang.py +20 -7
- package/scripts/route_log.py +26 -9
- package/scripts/route_policy.py +85 -6
- package/scripts/route_telemetry_export.py +199 -0
- package/scripts/rrf_classic.py +5 -22
- package/scripts/search.py +2 -1
- package/scripts/search_attribution.py +53 -10
- package/scripts/search_entry.py +32 -1
- package/scripts/search_output.py +23 -11
- package/scripts/search_pipeline.py +15 -3
- package/scripts/search_rank.py +21 -11
- package/scripts/semantic_evidence.py +394 -178
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +4 -3
- package/scripts/single_flight.py +1 -1
- package/scripts/social_engines/hackernews_engine.py +2 -1
- package/scripts/social_engines/reddit_engine.py +2 -1
- package/scripts/social_engines/xiaohongshu_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +252 -43
- package/scripts/sogou_weixin_browser.py +5 -6
- package/scripts/source_audit.py +44 -9
- package/scripts/source_ledger.py +2 -15
- package/scripts/source_selection.py +45 -20
- package/scripts/straggler_policy.py +1 -2
- package/scripts/sync_backends.py +17 -0
- package/scripts/tfidf_router.py +23 -11
- package/scripts/time_utils.py +54 -1
- package/scripts/train.py +68 -2
- package/scripts/usage_log.py +50 -10
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +70 -0
- package/sub-skills/ego-search/{SKILL.md → README.md} +15 -47
- package/sub-skills/ego-search/scripts/ego_search.py +13 -4
- package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
- package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
- package/sub-skills/local-search/engine_registry.py +32 -7
- package/sub-skills/local-seek/SKILL.md +20 -22
- package/sub-skills/local-seek/scripts/seek_fts.py +58 -3
- package/scripts/caliber_dedupe.py +0 -66
- package/scripts/engines_builders_batch16.py +0 -13
- package/scripts/health_probe.py +0 -253
- package/scripts/social_engines/twitter_engine.py +0 -514
- package/scripts/sync_installs.py +0 -29
|
@@ -394,9 +394,9 @@ def run_dispatch(*, query: str, retrieval_query: str, engines: list[str],
|
|
|
394
394
|
f"缺少环境变量:{' / '.join(missing_env)}(配置后重试)")
|
|
395
395
|
return eng, [], outcome, lat
|
|
396
396
|
|
|
397
|
-
# 时间窗只隔离带时间能力引擎的 per-engine 缓存(与 combo
|
|
398
|
-
eng_since = since_iso if is_time_capable(eng) else None
|
|
399
|
-
eng_until = until_iso if is_time_capable(eng) else None
|
|
397
|
+
# 时间窗只隔离带时间能力引擎的 per-engine 缓存(与 combo 键同语义);判空在前免白烧
|
|
398
|
+
eng_since = since_iso if (since_iso or until_iso) and is_time_capable(eng) else None
|
|
399
|
+
eng_until = until_iso if (since_iso or until_iso) and is_time_capable(eng) else None
|
|
400
400
|
|
|
401
401
|
# 远端配额耗尽:配额状态机已标记的引擎不参与调用。
|
|
402
402
|
# route_combo 的 F7 只覆盖 combo 路由;主路由(TF-IDF)/
|
|
@@ -537,8 +537,11 @@ def run_dispatch(*, query: str, retrieval_query: str, engines: list[str],
|
|
|
537
537
|
outcome["status"] = _mapped
|
|
538
538
|
outcome["detail"] = _text or outcome.get("detail")
|
|
539
539
|
if _note:
|
|
540
|
-
#
|
|
541
|
-
# 事后只能看到 kind
|
|
540
|
+
# 归因随熔断状态一起持久化(「为什么坏」必须在失败现场写下来,
|
|
541
|
+
# 事后只能看到 kind 粗标签);原始 HTTP 状态码同时透传进 outcome,
|
|
542
|
+
# 台账结构化可检 403/404/429,不再只埋在 detail 自由文本里。
|
|
543
|
+
if _note.get("status"):
|
|
544
|
+
outcome["http_status"] = int(_note["status"])
|
|
542
545
|
try:
|
|
543
546
|
from engine_failure import from_note
|
|
544
547
|
_attr = from_note(_note, eng)
|
package/scripts/engine_env.py
CHANGED
|
@@ -158,10 +158,69 @@ def reset_envfile_cache() -> None:
|
|
|
158
158
|
需要强制重读的调用方(测试隔离、密钥热更新)都走这里,别再各自操作
|
|
159
159
|
那两个全局变量:只做一半的状态在测试里几乎看不出来,排查成本极高。
|
|
160
160
|
"""
|
|
161
|
-
global _envfile_cache, _envfile_sig
|
|
161
|
+
global _envfile_cache, _envfile_sig, _zhihu_keychain_cache
|
|
162
162
|
with _envfile_lock:
|
|
163
163
|
_envfile_cache = {}
|
|
164
164
|
_envfile_sig = ()
|
|
165
|
+
_zhihu_keychain_cache = None
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# (monotonic 读取时刻, 值)。非空值黏进程生命周期(envfile 写回 reset 时清除,
|
|
169
|
+
# 与密钥轮换联动);空值(Keychain 超时/未录入)只黏短 TTL——否则 daemon/MCP
|
|
170
|
+
# 长驻进程首次读失败(如安全弹窗未应答)会让知乎全族整进程判缺钥且无自愈。
|
|
171
|
+
_ZHIHU_KEYCHAIN_NEG_TTL_S = 60.0
|
|
172
|
+
_zhihu_keychain_cache: tuple[float, str] | None = None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _decode_keyring_secret(raw: str) -> str:
|
|
176
|
+
raw = (raw or "").strip()
|
|
177
|
+
if raw.startswith("go-keyring-base64:"):
|
|
178
|
+
import base64
|
|
179
|
+
_, b64_val = raw.split(":", 1)
|
|
180
|
+
return base64.b64decode(b64_val).decode("utf-8", "replace").strip()
|
|
181
|
+
return raw
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _read_zhihu_keychain() -> str:
|
|
185
|
+
"""跨平台读取系统凭证库中知乎官方 CLI 管理的 Access Secret(macOS Keychain / Linux secret-tool / Windows keyring)。"""
|
|
186
|
+
global _zhihu_keychain_cache
|
|
187
|
+
import time as _time
|
|
188
|
+
with _envfile_lock:
|
|
189
|
+
if _zhihu_keychain_cache is not None:
|
|
190
|
+
_ts, _val = _zhihu_keychain_cache
|
|
191
|
+
# 非空值长期有效;空值短 TTL 后重探(自愈对称:envfile 有签名
|
|
192
|
+
# 热读,keychain 也不能黏死)
|
|
193
|
+
if _val or (_time.monotonic() - _ts) < _ZHIHU_KEYCHAIN_NEG_TTL_S:
|
|
194
|
+
return _val
|
|
195
|
+
import shutil
|
|
196
|
+
import sys
|
|
197
|
+
val = ""
|
|
198
|
+
try:
|
|
199
|
+
import subprocess
|
|
200
|
+
if sys.platform == "darwin":
|
|
201
|
+
raw = subprocess.check_output(
|
|
202
|
+
["security", "find-generic-password", "-s", "zhihu-cli", "-a", "access-secret", "-w"],
|
|
203
|
+
stderr=subprocess.DEVNULL, timeout=1.5,
|
|
204
|
+
).decode("utf-8", "replace")
|
|
205
|
+
val = _decode_keyring_secret(raw)
|
|
206
|
+
elif sys.platform.startswith("linux") and shutil.which("secret-tool"):
|
|
207
|
+
raw = subprocess.check_output(
|
|
208
|
+
["secret-tool", "lookup", "service", "zhihu-cli", "account", "access-secret"],
|
|
209
|
+
stderr=subprocess.DEVNULL, timeout=1.5,
|
|
210
|
+
).decode("utf-8", "replace")
|
|
211
|
+
val = _decode_keyring_secret(raw)
|
|
212
|
+
elif sys.platform.startswith("win"):
|
|
213
|
+
try:
|
|
214
|
+
import keyring # 可选系统依赖,不强绑
|
|
215
|
+
got = keyring.get_password("zhihu-cli", "access-secret")
|
|
216
|
+
val = _decode_keyring_secret(got or "")
|
|
217
|
+
except ImportError:
|
|
218
|
+
val = ""
|
|
219
|
+
except Exception:
|
|
220
|
+
val = ""
|
|
221
|
+
with _envfile_lock:
|
|
222
|
+
_zhihu_keychain_cache = (_time.monotonic(), val)
|
|
223
|
+
return val
|
|
165
224
|
|
|
166
225
|
# 引擎 → 候选环境变量(从左到右优先)
|
|
167
226
|
# 第一项为推荐新名(ARGO_ 前缀),后续为历史兼容名
|
|
@@ -181,6 +240,8 @@ KNOWN_ENV_ALIASES: dict[str, list[str]] = {
|
|
|
181
240
|
"zhihu": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
182
241
|
"zhihu_global": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
183
242
|
"zhihu_hot": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
243
|
+
"zhihu_questions": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
244
|
+
"zhihu_kb": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
184
245
|
"zhihu_user": ["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"],
|
|
185
246
|
"anysearch": ["ARGO_ANYSEARCH_API_KEY", "ANYSEARCH_API_KEY"], # 可选
|
|
186
247
|
"firecrawl": ["ARGO_FIRECRAWL_API_KEY", "FIRECRAWL_API_KEY"], # 可选(keyless 免费层)
|
|
@@ -272,6 +333,16 @@ def get_env(names: str | list[str], default: str = "") -> str:
|
|
|
272
333
|
val = file_env.get(name)
|
|
273
334
|
if val is not None and str(val).strip() != "":
|
|
274
335
|
return str(val)
|
|
336
|
+
|
|
337
|
+
# 凭证回退:macOS Keychain(zhihu-cli 统一凭据托管);显式置空 "" 时跳过回退
|
|
338
|
+
zhihu_keys = {"ZHIHU_ACCESS_SECRET", "ARGO_ZHIHU_ACCESS_SECRET"}
|
|
339
|
+
if any(n in zhihu_keys for n in names):
|
|
340
|
+
explicit_empty = any(n in zhihu_keys and n in os.environ and os.environ[n] == "" for n in names)
|
|
341
|
+
if not explicit_empty:
|
|
342
|
+
kc = _read_zhihu_keychain()
|
|
343
|
+
if kc:
|
|
344
|
+
return kc
|
|
345
|
+
|
|
275
346
|
return default
|
|
276
347
|
|
|
277
348
|
|
|
@@ -530,6 +601,125 @@ def env_status_for(engine_id: str, spec: dict[str, Any] | None = None) -> dict[s
|
|
|
530
601
|
}
|
|
531
602
|
|
|
532
603
|
|
|
604
|
+
# ── 子进程最小环境白名单 & 占位符作用域隔离 ──────────────────────────────────
|
|
605
|
+
# CLI 子进程只继承运行必需的非敏感环境变量 + 该引擎显式声明的 required_env /
|
|
606
|
+
# allowed_env / KNOWN_ENV_ALIASES,避免无关 API key 随 os.environ.copy() 泄露。
|
|
607
|
+
BASE_CHILD_ENV_ALLOWLIST: frozenset[str] = frozenset({
|
|
608
|
+
"PATH", "HOME", "USER", "LOGNAME", "USERNAME", "SHELL",
|
|
609
|
+
"TMPDIR", "TEMP", "TMP", "PWD",
|
|
610
|
+
"LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", "TERM", "COLORTERM", "NO_COLOR",
|
|
611
|
+
"PYTHONUTF8", "PYTHONIOENCODING", "PYTHONPATH", "VIRTUAL_ENV",
|
|
612
|
+
"XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME",
|
|
613
|
+
"APPDATA", "LOCALAPPDATA", "USERPROFILE", "SYSTEMROOT", "COMSPEC", "PATHEXT",
|
|
614
|
+
"SSL_CERT_FILE", "SSL_CERT_DIR", "REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE",
|
|
615
|
+
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
|
|
616
|
+
"http_proxy", "https_proxy", "all_proxy", "no_proxy",
|
|
617
|
+
"ARGO_STATE_DIR", "ARGO_ADMISSION_DIR", "ARGO_PROXY",
|
|
618
|
+
"ARGO_ALLOW_PRIVATE_URLS", "ARGO_ENGINE_HTTP_CLIENT", "ARGO_ENV_FILE",
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
def _flatten_env_names(raw: Any) -> list[str]:
|
|
623
|
+
out: list[str] = []
|
|
624
|
+
if isinstance(raw, str):
|
|
625
|
+
s = raw.strip()
|
|
626
|
+
if s:
|
|
627
|
+
out.append(s)
|
|
628
|
+
elif isinstance(raw, (list, tuple, set, frozenset)):
|
|
629
|
+
for item in raw:
|
|
630
|
+
out.extend(_flatten_env_names(item))
|
|
631
|
+
return out
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def _expand_allowed_names(names: list[str]) -> frozenset[str]:
|
|
635
|
+
allowed: set[str] = set()
|
|
636
|
+
for name in names:
|
|
637
|
+
allowed.add(name)
|
|
638
|
+
allowed.update(_name_variants(name))
|
|
639
|
+
for alias in PLACEHOLDER_ALIASES.get(name, ()):
|
|
640
|
+
allowed.add(alias)
|
|
641
|
+
allowed.update(_name_variants(alias))
|
|
642
|
+
for ph_key, candidates in PLACEHOLDER_ALIASES.items():
|
|
643
|
+
if name in candidates:
|
|
644
|
+
allowed.add(ph_key)
|
|
645
|
+
allowed.update(candidates)
|
|
646
|
+
return frozenset(allowed)
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
def allowed_placeholders_for(engine_id: str, spec: dict[str, Any] | None = None) -> frozenset[str]:
|
|
650
|
+
"""返回单引擎被授权读取/展开的 env 变量与占位符白名单。
|
|
651
|
+
|
|
652
|
+
来源仅限 spec.required_env、spec.allowed_env 与 KNOWN_ENV_ALIASES[engine_id],
|
|
653
|
+
不反推模板里的 {VAR},从而阻止 Confused Deputy 越权展开其他引擎密钥。
|
|
654
|
+
"""
|
|
655
|
+
names: list[str] = []
|
|
656
|
+
if isinstance(spec, dict):
|
|
657
|
+
names.extend(_flatten_env_names(spec.get("required_env")))
|
|
658
|
+
names.extend(_flatten_env_names(spec.get("allowed_env")))
|
|
659
|
+
if engine_id and engine_id in KNOWN_ENV_ALIASES:
|
|
660
|
+
names.extend(KNOWN_ENV_ALIASES[engine_id])
|
|
661
|
+
return _expand_allowed_names(names)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def resolve_env_placeholders(
|
|
665
|
+
text: str,
|
|
666
|
+
allowed_env: frozenset[str] | set[str] | None = None,
|
|
667
|
+
engine_id: str = "",
|
|
668
|
+
) -> str:
|
|
669
|
+
"""展开模板中残留的 {ENV_VAR} 占位符;传入 allowed_env 时强制白名单校验。"""
|
|
670
|
+
def _sub(m: re.Match[str]) -> str:
|
|
671
|
+
key = m.group(1)
|
|
672
|
+
if key in _NON_SECRET_PLACEHOLDERS:
|
|
673
|
+
return get_env([f"ARGO_{key}", key], "")
|
|
674
|
+
if allowed_env is not None and key not in allowed_env:
|
|
675
|
+
import logging
|
|
676
|
+
logging.getLogger("argo.env").warning(
|
|
677
|
+
f"引擎 {engine_id or '?'} 模板占位符 {{{key}}} 未在 required_env/allowed_env 中声明,已阻断展开"
|
|
678
|
+
)
|
|
679
|
+
return ""
|
|
680
|
+
candidates = PLACEHOLDER_ALIASES.get(key) or _name_variants(key)
|
|
681
|
+
return get_env(candidates, "")
|
|
682
|
+
|
|
683
|
+
return _PLACEHOLDER_RE.sub(_sub, text)
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def build_child_env(
|
|
687
|
+
engine_id: str,
|
|
688
|
+
spec: dict[str, Any] | None = None,
|
|
689
|
+
*,
|
|
690
|
+
extra_env: dict[str, str | None] | None = None,
|
|
691
|
+
base_env: dict[str, str] | None = None,
|
|
692
|
+
) -> dict[str, str]:
|
|
693
|
+
"""构建隔离后的 CLI 子进程环境变量字典(最小基础集 + 引擎授权集)。"""
|
|
694
|
+
source = base_env if base_env is not None else os.environ
|
|
695
|
+
allowed = allowed_placeholders_for(engine_id, spec)
|
|
696
|
+
out: dict[str, str] = {}
|
|
697
|
+
for k in BASE_CHILD_ENV_ALLOWLIST:
|
|
698
|
+
if k in source:
|
|
699
|
+
out[k] = source[k]
|
|
700
|
+
envfile = _envfile_load() if base_env is None else {}
|
|
701
|
+
for k in sorted(allowed):
|
|
702
|
+
if k in source:
|
|
703
|
+
out[k] = source[k]
|
|
704
|
+
elif k in envfile and envfile[k]:
|
|
705
|
+
out[k] = envfile[k]
|
|
706
|
+
if isinstance(spec, dict):
|
|
707
|
+
spec_env = spec.get("env")
|
|
708
|
+
if isinstance(spec_env, dict):
|
|
709
|
+
for k, v in spec_env.items():
|
|
710
|
+
if v is not None:
|
|
711
|
+
out[str(k)] = resolve_env_placeholders(
|
|
712
|
+
str(v), allowed_env=allowed, engine_id=engine_id
|
|
713
|
+
)
|
|
714
|
+
if extra_env:
|
|
715
|
+
for k, v in extra_env.items():
|
|
716
|
+
if v is None:
|
|
717
|
+
out.pop(str(k), None)
|
|
718
|
+
else:
|
|
719
|
+
out[str(k)] = str(v)
|
|
720
|
+
return out
|
|
721
|
+
|
|
722
|
+
|
|
533
723
|
# ── CLI 入口的 env 文件自动同步 ──────────────────────────────────────────────
|
|
534
724
|
# MCP server 在入口显式调 sync_envfile_to_environ();CLI 的 scripts/*.py 此前
|
|
535
725
|
# 没有任何同步点,导致约 22 处 os.environ 直读的 ARGO_* 开关在 CLI 下不认
|
|
@@ -41,6 +41,7 @@ engine_families.py — 搜索源能力族分类(第一性原理重构)
|
|
|
41
41
|
|
|
42
42
|
from __future__ import annotations
|
|
43
43
|
|
|
44
|
+
import re
|
|
44
45
|
from typing import Any
|
|
45
46
|
|
|
46
47
|
# ── 引擎 → 能力族 映射(config.yaml 引擎声明的 family 字段优先,本表保底) ──
|
|
@@ -138,6 +139,8 @@ _ENGINE_FAMILY_OVERRIDES: dict[str, str] = {
|
|
|
138
139
|
"local_google_news": "news_flash",
|
|
139
140
|
# 社区 UGC
|
|
140
141
|
"zhihu": "social",
|
|
142
|
+
"zhihu_questions": "social",
|
|
143
|
+
"zhihu_kb": "personal_data",
|
|
141
144
|
"v2ex": "social",
|
|
142
145
|
"juejin": "social",
|
|
143
146
|
"reddit": "social",
|
|
@@ -348,6 +351,12 @@ _ENGINE_FAMILY_OVERRIDES: dict[str, str] = {
|
|
|
348
351
|
"faz": "world_news", "nhk": "world_news", "matichon": "world_news",
|
|
349
352
|
"vnpress": "world_news", "antara": "world_news", "hurriyet": "world_news",
|
|
350
353
|
"ynet": "world_news", "ct24": "world_news",
|
|
354
|
+
# 2026-11-11:三家国际新闻 RSS 从 hot_trending 移到 world_news 后必须
|
|
355
|
+
# 同步登记这里。不登记时行为取决于 engines 是否已加载 registry:
|
|
356
|
+
# pytest 单跑(spec 快照为空)走静态表、族判成 web_general,三家原样
|
|
357
|
+
# 保留;全量回归里前序用例已加载 registry,族判成 world_news,中文查询
|
|
358
|
+
# 按语言互斥把英文源全摘掉。同一个查询两种结果,正是静态表要防的。
|
|
359
|
+
"guardian_rss": "world_news", "france24": "world_news", "dw_news": "world_news",
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
# 族 → 展示名
|
|
@@ -388,6 +397,11 @@ FAMILY_LABELS: dict[str, str] = {
|
|
|
388
397
|
# 购物(2026-09-26 批次十):电商站内搜索登录墙/强反爬,六源均为 DDG
|
|
389
398
|
# site: 语法包装,回答「某商品在某平台的在售/价格」,不是通用网页检索。
|
|
390
399
|
"shopping": "购物",
|
|
400
|
+
# AI 实验室一手博客(2026-11-15,随 ai_labs 引擎):官方公告与研究原文
|
|
401
|
+
# 直连,回答「某实验室自己发布了什么」。单列一族:与 news_flash(财经
|
|
402
|
+
# 快讯)和 world_news(各国本地新闻流)都不同——它是机构第一方信源,
|
|
403
|
+
# 显式专用(explicit_only),不参与同族 max_per_family=2 的槽位竞争。
|
|
404
|
+
"ai_labs": "AI 实验室一手",
|
|
391
405
|
}
|
|
392
406
|
|
|
393
407
|
|
|
@@ -416,6 +430,7 @@ ENGINE_LANGS: dict[str, list[str]] = {
|
|
|
416
430
|
"openalex": ["en"], "europepmc": ["en"],
|
|
417
431
|
# 中文专用(对 en/ja/ko 几乎零召回)
|
|
418
432
|
"zhihu": ["zh"], "zhihu_global": ["zh"], "zhihu_hot": ["zh"],
|
|
433
|
+
"zhihu_questions": ["zh"], "zhihu_kb": ["zh"],
|
|
419
434
|
"zhihu_user": ["zh"], "zhihu_content": ["zh"],
|
|
420
435
|
"bilibili": ["zh"], "v2ex": ["zh"], "xiaohongshu": ["zh"],
|
|
421
436
|
"weibo": ["zh"], "baidu_baike": ["zh"], "moegirl": ["zh"],
|
|
@@ -486,28 +501,48 @@ _SCRIPT_FAMILY_LANGS: dict[str, tuple[str, ...]] = {
|
|
|
486
501
|
# 这类词在查询里出现,说明用户就是在用那种语言问「有什么新闻」。方向仍然是
|
|
487
502
|
# 单向的——只在路由层做「查询语言 → 该语言源」的候选收窄,不改写查询、
|
|
488
503
|
# 不参与语言能力加权,判定失误的代价仅限于选源顺序。
|
|
504
|
+
# 拉丁/常见多语种实词兜底表:仅用于 `lang_detect` 只给不出具体语种时的选源与分桶
|
|
505
|
+
# 细化;短 ASCII 词走全词边界匹配,避免误伤英文(如 haberdasher)。
|
|
489
506
|
_LANG_HINT_WORDS: dict[str, tuple[str, ...]] = {
|
|
490
507
|
"ko": ("뉴스",), "ru": ("новости",), "ar": ("أخبار",),
|
|
491
|
-
"es": ("noticias",
|
|
492
|
-
"
|
|
493
|
-
"
|
|
508
|
+
"es": ("noticias", "últimas noticias", "español", "qué es"),
|
|
509
|
+
"pt": ("notícias", "português", "o que é"),
|
|
510
|
+
"fr": ("actualités", "nouvelles", "français", "qu'est-ce"),
|
|
511
|
+
"de": ("nachrichten", "aktuell", "deutsch", "was ist", "warum"),
|
|
512
|
+
"ja": ("ニュース",), "th": ("ข่าว",),
|
|
513
|
+
"vi": ("tin tức", "tiếng việt", "là gì"),
|
|
514
|
+
"id": ("berita", "terbaru", "bahasa indonesia", "apa itu"),
|
|
515
|
+
"tr": ("haberler", "gündem", "türkçe", "nedir"),
|
|
516
|
+
"it": ("notizie", "italiano", "cos'è", "che cos'è"),
|
|
494
517
|
"he": ("חדשות",), "cs": ("zprávy",),
|
|
495
518
|
}
|
|
496
519
|
|
|
520
|
+
_LANG_HINT_MATCHERS: list[tuple[str, re.Pattern[str] | None, str]] = [
|
|
521
|
+
(
|
|
522
|
+
lang,
|
|
523
|
+
re.compile(rf"\b{re.escape(w.lower())}\b") if w.isascii() else None,
|
|
524
|
+
w.lower(),
|
|
525
|
+
)
|
|
526
|
+
for lang, words in _LANG_HINT_WORDS.items()
|
|
527
|
+
for w in words
|
|
528
|
+
]
|
|
529
|
+
|
|
497
530
|
|
|
498
531
|
def lang_hint_from_query(query: str) -> str:
|
|
499
532
|
"""从查询文本里的实词推断语言;无命中返回 ""。
|
|
500
533
|
|
|
501
|
-
|
|
534
|
+
只服务「本地语言源选源与分桶」场景,不替代 lang_detect:调用方应在
|
|
502
535
|
语言判定给不出具体语种(en/latin/mixed)时才用它。
|
|
503
536
|
"""
|
|
504
537
|
low = (query or "").lower()
|
|
505
538
|
if not low:
|
|
506
539
|
return ""
|
|
507
|
-
for lang,
|
|
508
|
-
|
|
509
|
-
if
|
|
540
|
+
for lang, pattern, needle in _LANG_HINT_MATCHERS:
|
|
541
|
+
if pattern is not None:
|
|
542
|
+
if pattern.search(low):
|
|
510
543
|
return lang
|
|
544
|
+
elif needle in low:
|
|
545
|
+
return lang
|
|
511
546
|
return ""
|
|
512
547
|
|
|
513
548
|
|
|
@@ -578,6 +613,14 @@ def engines_demote_for_lang(engines: list[str], lang: str,
|
|
|
578
613
|
langs = engine_langs(e, spec)
|
|
579
614
|
if "*" in langs or lang in langs:
|
|
580
615
|
continue
|
|
616
|
+
# 查询语言只判到书写系统时(cyrillic/arabic/hebrew/thai…)先按语系
|
|
617
|
+
# 展开判定:cyrillic 查询曾把声明 ru 的 tass 自己移尾(ru 既不含
|
|
618
|
+
# 字面 cyrillic 也不含 en),匹配语言源被挤出预算窗口(2026-11-15
|
|
619
|
+
# world_news ru 两红)。展开判据与 lang_allows/_SCRIPT_FAMILY_LANGS
|
|
620
|
+
# 同源,只在此处补判定、不改 langs 本身。
|
|
621
|
+
if _SCRIPT_FAMILY_LANGS.get(lang) and any(
|
|
622
|
+
code in langs for code in _SCRIPT_FAMILY_LANGS[lang]):
|
|
623
|
+
continue
|
|
581
624
|
if lang == "zh":
|
|
582
625
|
if family_of(e, spec) == "social":
|
|
583
626
|
out.append(e)
|
package/scripts/engine_states.py
CHANGED
|
@@ -57,8 +57,6 @@ Python→JS 词表投影,堵住「登记完又退回裸字面量」与跨侧
|
|
|
57
57
|
not_found / unknown;结论 go / go_with_skips / stop
|
|
58
58
|
16. 数值印证(numeric verdict):confirmed / partial / missing / unfetchable
|
|
59
59
|
17. 取证覆盖(coverage):COVERED / PARTIAL / NOT_COVERED
|
|
60
|
-
18. 健康探针(probe status):available / degraded / unavailable / unknown
|
|
61
|
-
(health_probe 落库值;health_check 只写布尔 available)
|
|
62
60
|
19. 缓存层级(cache level):L1 / L2 / L?(未知兜底)
|
|
63
61
|
20. 候选核验(verification):candidate / opened
|
|
64
62
|
21. 观察模式变更(watch change):none / noise / substantive / unknown
|
|
@@ -433,8 +431,9 @@ def is_degraded_fetch_method(method: str) -> bool:
|
|
|
433
431
|
# ── 10. 平台/运行时状态(dsh-plugin / daemon)──────────────────────────────
|
|
434
432
|
# 生产端已收口:`scripts/daemon.py` 的 ping 响应与 `status` 子命令都带
|
|
435
433
|
# machine-readable 的 `state` 字段,值取自本表;进程停止时 status 报
|
|
436
|
-
# DAEMON_STOPPED(此时没有 ping
|
|
437
|
-
#
|
|
434
|
+
# DAEMON_STOPPED(此时没有 ping 可回)。ZCode 面板桥(py_bridge.py)此前直接
|
|
435
|
+
# 读这个字段,不再从中文文案反推 pid、也不再用布尔冒充三态——桥随 2026-11-13
|
|
436
|
+
# packages/argo-zcode 剥离退出,字段契约由 daemon.py 侧继续履行。
|
|
438
437
|
#
|
|
439
438
|
# 未收口的部分(JS 侧,本文件当前不是 JS 真源):
|
|
440
439
|
# - DSH 插件 `packages/dsh-plugin/dsh/client.js` 的 ready/loading/unavailable
|
|
@@ -565,45 +564,6 @@ COVERAGE_STATUSES = frozenset({
|
|
|
565
564
|
})
|
|
566
565
|
|
|
567
566
|
|
|
568
|
-
# ── 16. 健康探针(probe status)────────────────────────────────────────────
|
|
569
|
-
# health_probe 的 engine_health.status 列:连续失败未达阈值记 degraded,
|
|
570
|
-
# 达阈值记 unavailable,无记录记 unknown。health_check 另一条路径只写布尔
|
|
571
|
-
# available,不写这一列——两套视图并存是接口事实,不要合并。
|
|
572
|
-
|
|
573
|
-
PROBE_STATUS_AVAILABLE = "available"
|
|
574
|
-
PROBE_STATUS_DEGRADED = "degraded"
|
|
575
|
-
PROBE_STATUS_UNAVAILABLE = "unavailable"
|
|
576
|
-
PROBE_STATUS_UNKNOWN = "unknown"
|
|
577
|
-
|
|
578
|
-
PROBE_HEALTH_STATUSES = frozenset({
|
|
579
|
-
PROBE_STATUS_AVAILABLE, PROBE_STATUS_DEGRADED,
|
|
580
|
-
PROBE_STATUS_UNAVAILABLE, PROBE_STATUS_UNKNOWN,
|
|
581
|
-
})
|
|
582
|
-
|
|
583
|
-
# 连续失败达到该次数即判 unavailable(状态机转换条件,与状态名同源)。
|
|
584
|
-
# 此前 health_probe 与 health_check 各写一个 MAX_FAILURES = 2,且 health_check
|
|
585
|
-
# 那份没有任何读取点——改名也照样跑,等于两处「看起来有阈值」。
|
|
586
|
-
PROBE_MAX_FAILURES = 2
|
|
587
|
-
|
|
588
|
-
# 视为「可路由」的探针状态:只有 unavailable 是硬失败;degraded 是「连续
|
|
589
|
-
# 失败但未达阈值」,unknown 是「没探过」。后两者都放行——与
|
|
590
|
-
# health_probe.get_engine_status 的 available 判据(`!= "unavailable"`)逐位
|
|
591
|
-
# 一致,包括对未登记状态值的 fail-open(宁可放行,不让词表演进把源静默过滤)。
|
|
592
|
-
PROBE_ROUTABLE_STATUSES = frozenset({
|
|
593
|
-
PROBE_STATUS_AVAILABLE, PROBE_STATUS_DEGRADED, PROBE_STATUS_UNKNOWN,
|
|
594
|
-
})
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
def is_probe_available(status: str) -> bool:
|
|
598
|
-
"""探针状态是否允许参与路由(唯一判据:不是 unavailable)。
|
|
599
|
-
|
|
600
|
-
刻意不看 PROBE_ROUTABLE_STATUSES 白名单——历史行为就是「只认
|
|
601
|
-
unavailable 一票否决」,改成白名单会让未登记值(旧库/新版本回滚)从
|
|
602
|
-
「可用」静默变成「不可用」,把源过滤掉。
|
|
603
|
-
"""
|
|
604
|
-
return str(status or "") != PROBE_STATUS_UNAVAILABLE
|
|
605
|
-
|
|
606
|
-
|
|
607
567
|
# ── 17. 缓存层级(cache level)─────────────────────────────────────────────
|
|
608
568
|
CACHE_LEVEL_L1 = "L1"
|
|
609
569
|
CACHE_LEVEL_L2 = "L2"
|
|
@@ -942,13 +902,6 @@ register_state_machine(
|
|
|
942
902
|
description="取证覆盖:COVERED / PARTIAL / NOT_COVERED",
|
|
943
903
|
)
|
|
944
904
|
|
|
945
|
-
register_state_machine(
|
|
946
|
-
"probe",
|
|
947
|
-
states=PROBE_HEALTH_STATUSES,
|
|
948
|
-
routable=PROBE_ROUTABLE_STATUSES,
|
|
949
|
-
description="健康探针:available / degraded / unavailable / unknown",
|
|
950
|
-
)
|
|
951
|
-
|
|
952
905
|
register_state_machine(
|
|
953
906
|
"cache",
|
|
954
907
|
states=CACHE_LEVELS,
|
|
@@ -39,11 +39,6 @@ from cli_io import dumps
|
|
|
39
39
|
|
|
40
40
|
REQUIRED_KEYS = ("title", "url", "source")
|
|
41
41
|
|
|
42
|
-
# --apply 的最低置信度:diagnose_schema_drift 对「容器位移或 title+url 同时
|
|
43
|
-
# 命中」给 0.95,对「单字段启发式猜测」给 0.80。后者不足以自动改写 Spec
|
|
44
|
-
# 真源——改错了没有回滚凭据,必须留给人核对 suggested_patch。
|
|
45
|
-
_APPLY_MIN_CONFIDENCE = 0.95
|
|
46
|
-
|
|
47
42
|
# 垂类引擎 health canary(通用词会误杀快讯/行情类)
|
|
48
43
|
ENGINE_CANARY_QUERIES: dict[str, str] = {
|
|
49
44
|
"fxtwitter": "OpenAI",
|
|
@@ -513,13 +508,8 @@ def validate_engine(
|
|
|
513
508
|
write_doc: bool = False,
|
|
514
509
|
profile: str = "default",
|
|
515
510
|
diagnose: bool = False,
|
|
516
|
-
apply: bool = False,
|
|
517
511
|
) -> dict[str, Any]:
|
|
518
|
-
"""执行验证并可选写入 admission。
|
|
519
|
-
|
|
520
|
-
apply:是否把结构漂移诊断建议的 output_map 补丁**写回 Spec 真源**。
|
|
521
|
-
默认 False 只输出预览(report["suggested_patch"]),不碰磁盘。
|
|
522
|
-
"""
|
|
512
|
+
"""执行验证并可选写入 admission。diagnose=True 时只读输出结构漂移诊断。"""
|
|
523
513
|
stages = []
|
|
524
514
|
if stage == "all":
|
|
525
515
|
stages = [engine_states.VALIDATION_STAGE_CONTRACT,
|
|
@@ -631,37 +621,24 @@ def validate_engine(
|
|
|
631
621
|
path = _write_engine_doc(engine_id, report)
|
|
632
622
|
report["doc_path"] = str(path)
|
|
633
623
|
|
|
634
|
-
#
|
|
635
|
-
# --fix 是预览态:诊断结果进 report 供人过目,不写盘。
|
|
636
|
-
# --apply 才落盘,且要过置信度门槛——启发式选出的 0.80 建议不能
|
|
637
|
-
# 自动改写唯一真源 Spec(改错了没有回滚凭据)。
|
|
624
|
+
# 结构漂移只读诊断(针对声明式 HTTP 源,预览 suggested_patch 与样本键路径,不自动写盘)
|
|
638
625
|
spec = _get_spec(engine_id)
|
|
639
|
-
if
|
|
640
|
-
|
|
626
|
+
if diagnose or (report.get("status") == engine_states.VALIDATION_STATUS_FAIL
|
|
627
|
+
and spec.get("type") == "http"):
|
|
641
628
|
if spec.get("type") == "http" and (spec.get("output_map") or spec.get("response")):
|
|
642
629
|
try:
|
|
643
|
-
|
|
630
|
+
import engines_schema_drift
|
|
644
631
|
canary = spec.get("canary_query") or ENGINE_CANARY_QUERIES.get(engine_id) or "test"
|
|
645
632
|
raw_data = probe_engine_raw(engine_id, query=canary, timeout=timeout)
|
|
646
633
|
if raw_data is not None:
|
|
647
|
-
drift_diag = diagnose_schema_drift(raw_data, spec)
|
|
634
|
+
drift_diag = engines_schema_drift.diagnose_schema_drift(raw_data, spec)
|
|
648
635
|
report["schema_drift"] = drift_diag
|
|
649
636
|
suggested = drift_diag.get("suggested_patch") or {}
|
|
650
637
|
if suggested:
|
|
651
638
|
report["suggested_patch"] = suggested
|
|
652
|
-
if
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
spec_path = ROOT / "engines" / "specs" / f"{engine_id}.yaml"
|
|
656
|
-
ok, msg = apply_schema_patch(spec_path, suggested)
|
|
657
|
-
if ok:
|
|
658
|
-
report["fix_applied"] = True
|
|
659
|
-
report["fix_msg"] = msg
|
|
660
|
-
else:
|
|
661
|
-
report["fix_blocked_low_confidence"] = True
|
|
662
|
-
report["fix_msg"] = (
|
|
663
|
-
f"置信度 {confidence:.0%} 低于 {_APPLY_MIN_CONFIDENCE:.0%},"
|
|
664
|
-
"不自动改写 Spec;请人工核对 suggested_patch 后手动更新")
|
|
639
|
+
if drift_diag.get("shadow_verified") is not None:
|
|
640
|
+
report["shadow_verified"] = drift_diag.get("shadow_verified")
|
|
641
|
+
report["shadow_msg"] = drift_diag.get("shadow_msg")
|
|
665
642
|
except Exception as _ex:
|
|
666
643
|
report["schema_drift_error"] = str(_ex)
|
|
667
644
|
|
|
@@ -755,12 +732,8 @@ def main() -> int:
|
|
|
755
732
|
parser.add_argument("--diagnose", action="store_true",
|
|
756
733
|
help="对声明式 HTTP 引擎执行深入结构漂移诊断")
|
|
757
734
|
parser.add_argument("--fix", dest="fix_preview", action="store_true",
|
|
758
|
-
help="诊断并输出建议的 output_map
|
|
735
|
+
help="诊断并输出建议的 output_map 补丁(只读预览,不写盘);"
|
|
759
736
|
"等同于 --diagnose,保留旧命令名")
|
|
760
|
-
parser.add_argument("--apply", action="store_true",
|
|
761
|
-
help="将建议的 output_map 补丁写入对应 Spec 文件"
|
|
762
|
-
"(需置信度不低于 95 个百分点);"
|
|
763
|
-
"不显式给这个参数就绝不改写真源")
|
|
764
737
|
args = parser.parse_args()
|
|
765
738
|
|
|
766
739
|
targets: list[str] = []
|
|
@@ -784,7 +757,7 @@ def main() -> int:
|
|
|
784
757
|
rep = validate_engine(
|
|
785
758
|
eng, stage=stage, admit=admit, timeout=args.timeout,
|
|
786
759
|
write_doc=args.write_doc, profile=args.profile,
|
|
787
|
-
diagnose=args.diagnose or args.fix_preview,
|
|
760
|
+
diagnose=args.diagnose or args.fix_preview,
|
|
788
761
|
)
|
|
789
762
|
reports.append(rep)
|
|
790
763
|
if rep.get("status") == engine_states.VALIDATION_STATUS_FAIL:
|
|
@@ -809,15 +782,10 @@ def main() -> int:
|
|
|
809
782
|
err = h.get("error") or q.get("error") or rep.get("error")
|
|
810
783
|
print(f" error: {err}")
|
|
811
784
|
if rep.get("schema_drift"):
|
|
812
|
-
from
|
|
785
|
+
from engines_schema_drift import render_drift_report
|
|
813
786
|
print(render_drift_report(rep["schema_drift"], eng))
|
|
814
|
-
if rep.get("fix_applied"):
|
|
815
|
-
print(f" [apply] {rep.get('fix_msg', '已自动更新 Spec 文件')}")
|
|
816
|
-
elif rep.get("fix_blocked_low_confidence"):
|
|
817
|
-
print(f" [apply 未落盘] {rep.get('fix_msg')}")
|
|
818
787
|
elif rep.get("suggested_patch") and not args.json:
|
|
819
|
-
print(" [fix]
|
|
820
|
-
"确认无误后加 --apply 才落盘")
|
|
788
|
+
print(" [fix] 已给出建议补丁(只读预览,未写盘);请人工核对并更新对应 Spec")
|
|
821
789
|
|
|
822
790
|
if args.json:
|
|
823
791
|
payload = reports if len(reports) > 1 else reports[0]
|