argo-search 2.10.0 → 2.10.1
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/README.en.md +24 -10
- package/README.es.md +23 -9
- package/README.ja.md +24 -10
- package/README.ko.md +24 -10
- package/README.md +24 -10
- package/SKILL.md +11 -10
- package/backends/engine_registry.yaml +2 -2
- package/backends/source_types_cn.json +9 -0
- package/config.yaml +23 -10
- package/docs/ENGINE_CATALOG.md +8 -8
- package/docs/RELEASE_NOTES_v2.10.1.md +57 -0
- package/engines/_template_http.yaml +2 -0
- package/engines/specs/ncpssd.yaml +3 -0
- package/engines/specs/sciverse.yaml +1 -0
- package/package.json +3 -2
- package/packages/dsh-plugin/package.json +1 -1
- package/scripts/ci_drift_gate.py +47 -24
- package/scripts/engine_dispatch.py +6 -8
- package/scripts/engine_status.py +12 -5
- package/scripts/engines.py +5 -0
- package/scripts/engines_base.py +31 -15
- package/scripts/engines_builders_data.py +10 -3
- package/scripts/evidence.py +26 -5
- package/scripts/local_seek.py +53 -11
- package/scripts/mcp_transport.py +1 -1
- package/scripts/release.py +398 -0
- package/scripts/route_domains.py +18 -2
- package/scripts/search.py +4 -2
- package/scripts/search_cli.py +22 -0
- package/scripts/search_output.py +14 -0
- package/scripts/search_pipeline.py +4 -2
- package/scripts/search_rank.py +3 -1
- package/scripts/serp_guard.py +11 -0
- package/scripts/url_canon.py +2 -1
- package/scripts/video_route.py +3 -3
- package/sub-skills/local-seek/scripts/seek.py +19 -4
- package/engines/specs/_cisa_kev.yaml +0 -54
- package/engines/specs/_osv.yaml +0 -63
package/scripts/engine_status.py
CHANGED
|
@@ -106,8 +106,10 @@ def engine_detail(engine_id: str, spec: dict[str, Any] | None = None,
|
|
|
106
106
|
tiers: dict[str, list[str]] | None = None,
|
|
107
107
|
adaptive_scores: dict[str, float] | None = None,
|
|
108
108
|
quota_marks: dict[str, dict[str, Any]] | None = None) -> dict[str, Any]:
|
|
109
|
+
known = True
|
|
109
110
|
if spec is None:
|
|
110
111
|
specs = _all_engine_specs()
|
|
112
|
+
known = engine_id in specs
|
|
111
113
|
spec = specs.get(engine_id) or {}
|
|
112
114
|
tiers = tiers if tiers is not None else get_cost_tiers()
|
|
113
115
|
env = env_status_for(engine_id, spec)
|
|
@@ -115,7 +117,8 @@ def engine_detail(engine_id: str, spec: dict[str, Any] | None = None,
|
|
|
115
117
|
adm = load_admission(engine_id)
|
|
116
118
|
blocked = is_blocked(engine_id)
|
|
117
119
|
admitted = is_admitted(engine_id)
|
|
118
|
-
config_enabled = bool(spec.get("enabled", True))
|
|
120
|
+
config_enabled = bool(spec.get("enabled", True)) if known else False
|
|
121
|
+
disabled_reason = str(spec.get("disabled_reason") or "").strip() if not config_enabled else ""
|
|
119
122
|
allowed = env["allowed_by_env"]
|
|
120
123
|
env_ok = env["env_ready"]
|
|
121
124
|
dep_ok = deps["dep_ready"]
|
|
@@ -131,7 +134,8 @@ def engine_detail(engine_id: str, spec: dict[str, Any] | None = None,
|
|
|
131
134
|
# (--routable-only 的帮助文案与 available_engines 同一口径)。此前漏判,
|
|
132
135
|
# 旧显式源恰好被 env/dep 门挡住没暴露;toutiao(免 key 免依赖)把它炸出。
|
|
133
136
|
routable = (
|
|
134
|
-
|
|
137
|
+
known
|
|
138
|
+
and config_enabled
|
|
135
139
|
and allowed
|
|
136
140
|
and env_ok
|
|
137
141
|
and dep_ok
|
|
@@ -140,7 +144,9 @@ def engine_detail(engine_id: str, spec: dict[str, Any] | None = None,
|
|
|
140
144
|
and not bool(spec.get("explicit_only"))
|
|
141
145
|
)
|
|
142
146
|
status = "ready"
|
|
143
|
-
if not
|
|
147
|
+
if not known:
|
|
148
|
+
status = "unknown"
|
|
149
|
+
elif not config_enabled:
|
|
144
150
|
status = "disabled"
|
|
145
151
|
elif not allowed:
|
|
146
152
|
status = "env_filtered"
|
|
@@ -162,7 +168,8 @@ def engine_detail(engine_id: str, spec: dict[str, Any] | None = None,
|
|
|
162
168
|
return {
|
|
163
169
|
"engine_id": engine_id,
|
|
164
170
|
"enabled": config_enabled,
|
|
165
|
-
"
|
|
171
|
+
**({"disabled_reason": disabled_reason} if disabled_reason else {}),
|
|
172
|
+
"type": spec.get("type", "cli") if known else "unknown",
|
|
166
173
|
"cost_tier": _cost_tier_of(engine_id, tiers),
|
|
167
174
|
"status": status,
|
|
168
175
|
# 设计上不进自动路由(需密钥的付费源 / 输入形态特殊),按 --engine 显式调用;
|
|
@@ -224,7 +231,7 @@ def compact_engine_row(row: dict[str, Any]) -> dict[str, Any]:
|
|
|
224
231
|
"dep_ready": row.get("dep_ready"),
|
|
225
232
|
}
|
|
226
233
|
# 条件性细节:非空才出现(健康源不带这些键,输出不随异常源膨胀)
|
|
227
|
-
for key in ("missing_env", "missing_deps"):
|
|
234
|
+
for key in ("missing_env", "missing_deps", "disabled_reason"):
|
|
228
235
|
if row.get(key):
|
|
229
236
|
slim[key] = row[key]
|
|
230
237
|
if row.get("quota_exhausted") and row.get("quota_exhausted_reason"):
|
package/scripts/engines.py
CHANGED
|
@@ -801,6 +801,11 @@ def search(query: str, engine: str, n: int = 5, timeout: float = 8, depth: str =
|
|
|
801
801
|
# 的签名都不匹配,异常被 except 吞掉,从未生效过(2026-10-18 复核)。
|
|
802
802
|
# 不修它:单次失败就全局压制该引擎 45s,比熔断器「连续两次才打开」更激进,
|
|
803
803
|
# 会在一次网络抖动后误杀健康源。保持单一真源,避免第二套状态。
|
|
804
|
+
# 视频模式(--video / video_only=True)下,海外免费源 parallel_free 默认给网页,
|
|
805
|
+
# 附加 site:youtube.com 使其定向召回 YouTube 视频,避免被后续 video_only 滤空(issue #34.3)。
|
|
806
|
+
video_only = bool(kwargs.pop("video_only", False))
|
|
807
|
+
if video_only and engine == "parallel_free" and "site:" not in query.lower():
|
|
808
|
+
query = f"{query} site:youtube.com"
|
|
804
809
|
# 语义型引擎不识别平台结构化语法,剥掉字段只留核心词;透传型保持原 query。
|
|
805
810
|
if engine in _SEMANTIC_ENGINES:
|
|
806
811
|
query = strip_structured(query)
|
package/scripts/engines_base.py
CHANGED
|
@@ -27,8 +27,7 @@ except ImportError:
|
|
|
27
27
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
28
28
|
from config import load_config, get_engines
|
|
29
29
|
|
|
30
|
-
# 图片许可判定 / 字段收尾 / CLI 字段契约收敛都在 image_ops
|
|
31
|
-
# 且同属「引擎输出 → 对外契约」这一层)。转发导入保持调用点不变。
|
|
30
|
+
# 图片许可判定 / 字段收尾 / CLI 字段契约收敛都在 image_ops(转发导入保持调用点不变)。
|
|
32
31
|
from image_ops import ( # noqa: E402
|
|
33
32
|
CLI_PASSTHROUGH_FIELDS as _CLI_PASSTHROUGH_FIELDS,
|
|
34
33
|
_cli_result_row,
|
|
@@ -60,8 +59,7 @@ def _get_logger():
|
|
|
60
59
|
_FAIL_NOTES: dict[str, dict[str, Any]] = {}
|
|
61
60
|
_FAIL_NOTES_LOCK = threading.Lock()
|
|
62
61
|
|
|
63
|
-
# HTTPError
|
|
64
|
-
# 无限读会把几十 MB 错误页吃进内存并写进磁盘状态
|
|
62
|
+
# HTTPError 错误体读取上限:只用于归因(下游截 400 字符),防大错误页吃进内存/落盘
|
|
65
63
|
_HTTP_ERROR_BODY_CAP = 64 * 1024
|
|
66
64
|
|
|
67
65
|
# 归因细节里可能回显凭证(OpenAI 风格 "Incorrect API key: sk-…"),
|
|
@@ -322,11 +320,12 @@ def _coerce_field(val: Any, *, max_len: int | None = None) -> str:
|
|
|
322
320
|
|
|
323
321
|
|
|
324
322
|
def _format_url_template(template: str, item: dict) -> str:
|
|
325
|
-
"""支持 {field} 与 {a.b.c} 点分路径的 URL
|
|
326
|
-
|
|
327
|
-
|
|
323
|
+
"""支持 {field} 与 {a.b.c} 点分路径的 URL 模板;任一占位为空则返回空串。"""
|
|
324
|
+
vals = {m.group(1): _coerce_field(_get_path(item, m.group(1))) for m in re.finditer(r"\{([^}]+)\}", template)}
|
|
325
|
+
if any(not v for v in vals.values()):
|
|
326
|
+
return ""
|
|
328
327
|
try:
|
|
329
|
-
return re.sub(r"\{([^}]+)\}",
|
|
328
|
+
return re.sub(r"\{([^}]+)\}", lambda m: vals[m.group(1)], template)
|
|
330
329
|
except Exception:
|
|
331
330
|
return ""
|
|
332
331
|
|
|
@@ -365,7 +364,6 @@ def _make_field_parser(path: str, fields: dict[str, str], url_template: str | No
|
|
|
365
364
|
if not ik:
|
|
366
365
|
continue
|
|
367
366
|
raw = _get_path(item, ik) if "." in str(ik) else item.get(ik, "")
|
|
368
|
-
# 兼容顶层点分键名不存在时回退 get
|
|
369
367
|
if raw in ("", None) and "." not in str(ik):
|
|
370
368
|
raw = item.get(ik, "")
|
|
371
369
|
coerced = _coerce_field(raw, max_len=300 if ok == "snippet" else 500)
|
|
@@ -375,6 +373,8 @@ def _make_field_parser(path: str, fields: dict[str, str], url_template: str | No
|
|
|
375
373
|
built = _format_url_template(url_template, item)
|
|
376
374
|
if built.startswith(("http://", "https://")):
|
|
377
375
|
r["url"] = built
|
|
376
|
+
else:
|
|
377
|
+
r.pop("url", None)
|
|
378
378
|
if isinstance(r.get("url"), str) and r["url"].startswith("//"):
|
|
379
379
|
r["url"] = "https:" + r["url"]
|
|
380
380
|
if r.get("title") or r.get("url"):
|
|
@@ -406,8 +406,10 @@ def _build_cli_engine(spec: dict[str, Any]) -> Any:
|
|
|
406
406
|
args += _resolve(tmpl, query, n, mode=mode, **kwargs)
|
|
407
407
|
env = os.environ.copy()
|
|
408
408
|
env.update(env_overrides)
|
|
409
|
-
return
|
|
410
|
-
|
|
409
|
+
return _apply_url_kind(
|
|
410
|
+
_parse_text_output(_run(cmd + args, timeout=timeout, engine_name=spec.get("_name", "cli")),
|
|
411
|
+
spec.get("_name", "cli"), output_format=output_format, n=n),
|
|
412
|
+
spec)
|
|
411
413
|
return _engine
|
|
412
414
|
|
|
413
415
|
|
|
@@ -761,6 +763,18 @@ def _normalize_epoch(value: Any) -> str:
|
|
|
761
763
|
return text
|
|
762
764
|
|
|
763
765
|
|
|
766
|
+
def _apply_url_kind(rows: list[dict[str, Any]], spec: dict) -> list[dict[str, Any]]:
|
|
767
|
+
"""声明式 spec 的 url_kind 落到行上(issue #29 口径 B):none = 本档条目不以
|
|
768
|
+
url 为身份,缺 url 的条目不按壳页整批吞。spec 未声明时行上不出现该字段。"""
|
|
769
|
+
kind = spec.get("url_kind")
|
|
770
|
+
if not kind:
|
|
771
|
+
return rows
|
|
772
|
+
for r in rows:
|
|
773
|
+
if isinstance(r, dict):
|
|
774
|
+
r.setdefault("url_kind", kind)
|
|
775
|
+
return rows
|
|
776
|
+
|
|
777
|
+
|
|
764
778
|
def _parse_http_payload(raw: str, fmt: str, eng: str, n: int,
|
|
765
779
|
output_map: dict, spec: dict) -> list[dict[str, Any]]:
|
|
766
780
|
"""HTTP 引擎响应体解析(GET/POST 共用)。"""
|
|
@@ -781,7 +795,7 @@ def _parse_http_payload(raw: str, fmt: str, eng: str, n: int,
|
|
|
781
795
|
# 专用 JSON 解析器优先(DDG Instant Answer / UAPI / Semantic Scholar 等)
|
|
782
796
|
custom = _CUSTOM_JSON_PARSERS.get(eng)
|
|
783
797
|
if custom:
|
|
784
|
-
return _ensure_engine_source(custom(data), eng)[:limit]
|
|
798
|
+
return _apply_url_kind(_ensure_engine_source(custom(data), eng)[:limit], spec)
|
|
785
799
|
if output_map:
|
|
786
800
|
items_path = output_map.get("items", "")
|
|
787
801
|
# 根节点即为数组时(HF / dev.to / polymarket),items 用 "."
|
|
@@ -826,9 +840,11 @@ def _parse_http_payload(raw: str, fmt: str, eng: str, n: int,
|
|
|
826
840
|
# 自定义 builder、通用兜底),只覆盖一条会让契约对一半结果生效。
|
|
827
841
|
finalize_image_fields(parsed, _lic or "")
|
|
828
842
|
# preserve_source(声明式 spec):保留 API 返回的真实来源标注
|
|
829
|
-
return
|
|
830
|
-
|
|
831
|
-
|
|
843
|
+
return _apply_url_kind(
|
|
844
|
+
_ensure_engine_source(
|
|
845
|
+
parsed, eng, preserve=bool(spec.get("preserve_source"))
|
|
846
|
+
)[:limit],
|
|
847
|
+
spec)
|
|
832
848
|
if isinstance(data, list):
|
|
833
849
|
return _ensure_engine_source(
|
|
834
850
|
_parse_generic({"results": data}, eng, limit), eng
|
|
@@ -669,10 +669,12 @@ def _build_models_dev_engine(spec: dict[str, Any]) -> Any:
|
|
|
669
669
|
# ── Finviz 美股筛选引擎(HTML 抓取)─────────────────────────────────────────────
|
|
670
670
|
|
|
671
671
|
def _build_finviz_engine(spec: dict[str, Any]) -> Any:
|
|
672
|
-
"""Finviz 个股快照(finviz.com/
|
|
672
|
+
"""Finviz 个股快照(finviz.com/stock?t=TICKER)
|
|
673
673
|
|
|
674
674
|
从 snapshot 表格提取:公司名、行业、市值、PE、价格、涨跌幅。
|
|
675
675
|
query 视为 ticker(大写);非纯字母时取首个字母 token 作 ticker。
|
|
676
|
+
(2026-10-28:旧地址 /quote.ashx 全站 301 到 /stock,http_open 不跟随重定向,
|
|
677
|
+
端点随之切换;新页 snapshot 表结构与解析器兼容,实测 AAPL 全字段命中。)
|
|
676
678
|
"""
|
|
677
679
|
timeout = spec.get("timeout", 10)
|
|
678
680
|
|
|
@@ -683,7 +685,7 @@ def _build_finviz_engine(spec: dict[str, Any]) -> Any:
|
|
|
683
685
|
if not m:
|
|
684
686
|
return []
|
|
685
687
|
ticker = m.group(0).upper()
|
|
686
|
-
url = f"https://finviz.com/
|
|
688
|
+
url = f"https://finviz.com/stock?t={ticker}"
|
|
687
689
|
headers = {
|
|
688
690
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
|
|
689
691
|
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
@@ -2552,12 +2554,16 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
2552
2554
|
# ── OpenCorporates 全球公司注册 ──────────────────────────────────────────────
|
|
2553
2555
|
|
|
2554
2556
|
def _build_opencorporates_engine(spec: dict[str, Any]) -> Any:
|
|
2555
|
-
"""OpenCorporates 全球公司注册(api.opencorporates.com/v0.4/companies/search
|
|
2557
|
+
"""OpenCorporates 全球公司注册(api.opencorporates.com/v0.4/companies/search)。
|
|
2556
2558
|
|
|
2557
2559
|
公司尽调/反欺诈:公司名、注册号、司法辖区、成立日期、状态。
|
|
2558
2560
|
argo 现有引擎无公司注册数据源,这是尽调类查询的核心空白。
|
|
2561
|
+
(2026-10-28:匿名请求已被上游全面拒 401,API 需 api_token;直连实测确认。
|
|
2562
|
+
支持 ARGO_OPENCORPORATES_API_TOKEN / OPENCORPORATES_API_TOKEN 双别名,
|
|
2563
|
+
spec required_env 已声明,无 token 时被 env 门自动跳过而非报错。)
|
|
2559
2564
|
"""
|
|
2560
2565
|
timeout = spec.get("timeout", 10)
|
|
2566
|
+
_token = get_env(["ARGO_OPENCORPORATES_API_TOKEN", "OPENCORPORATES_API_TOKEN"]) or ""
|
|
2561
2567
|
|
|
2562
2568
|
@safe_search
|
|
2563
2569
|
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
@@ -2569,6 +2575,7 @@ def _build_opencorporates_engine(spec: dict[str, Any]) -> Any:
|
|
|
2569
2575
|
url = (
|
|
2570
2576
|
"https://api.opencorporates.com/v0.4/companies/search"
|
|
2571
2577
|
f"?q={urllib.parse.quote(q2)}&per_page={min(n, 10)}"
|
|
2578
|
+
+ (f"&api_token={urllib.parse.quote(_token)}" if _token else "")
|
|
2572
2579
|
)
|
|
2573
2580
|
headers = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
|
|
2574
2581
|
try:
|
package/scripts/evidence.py
CHANGED
|
@@ -152,7 +152,7 @@ from serp_guard import ( # noqa: E402
|
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
@functools.lru_cache(maxsize=512)
|
|
155
|
-
def _score_authority_cached(url: str, source: str = "") -> tuple:
|
|
155
|
+
def _score_authority_cached(url: str, source: str = "", query: str = "") -> tuple:
|
|
156
156
|
"""score_authority 的缓存版本,返回 tuple(lru_cache 要求可哈希返回值)。"""
|
|
157
157
|
if not url:
|
|
158
158
|
return (0.3, "无 URL", "unknown", "", True)
|
|
@@ -228,6 +228,24 @@ def _score_authority_cached(url: str, source: str = "") -> tuple:
|
|
|
228
228
|
else:
|
|
229
229
|
best_reason += f"(引擎={source})"
|
|
230
230
|
|
|
231
|
+
# 有条件降权(2026-10-29,issue #34):同一域名在不同查询语境下可信度
|
|
232
|
+
# 不同——裁判文书站对「集采政策」是答非所问,对「判决书检索」是一手源。
|
|
233
|
+
# 放在引擎保底分之后做**最终裁决**:否则 anysearch 这类引擎的 0.75 保底
|
|
234
|
+
# 会把降权分拉回来(实测 0.15 → 0.75,降权形同虚设)。
|
|
235
|
+
# 只在调用方给了 query 时生效:无 query 的评分路径(状态展示、研究摘要)
|
|
236
|
+
# 保持原表行为,避免把「没传上下文」误判成「非法律查询」。
|
|
237
|
+
if query:
|
|
238
|
+
cond = _load_cn_source_types().get("demote_domains_unless") or {}
|
|
239
|
+
for d, meta in cond.items():
|
|
240
|
+
if d.startswith("_"):
|
|
241
|
+
continue
|
|
242
|
+
if domain == d or domain.endswith("." + d):
|
|
243
|
+
unless = meta.get("unless") or ""
|
|
244
|
+
if not (unless and re.search(unless, query, re.I)):
|
|
245
|
+
best_score = float(meta.get("score", 0.3))
|
|
246
|
+
best_reason = f"降权:{meta.get('reason', d)}"
|
|
247
|
+
break
|
|
248
|
+
|
|
231
249
|
tier = (
|
|
232
250
|
"high" if best_score >= 0.8
|
|
233
251
|
else "medium" if best_score >= 0.6
|
|
@@ -238,14 +256,17 @@ def _score_authority_cached(url: str, source: str = "") -> tuple:
|
|
|
238
256
|
return (best_score, best_reason, tier, domain, bool(is_serp))
|
|
239
257
|
|
|
240
258
|
|
|
241
|
-
def score_authority(url: str, source: str = "") -> dict[str, Any]:
|
|
259
|
+
def score_authority(url: str, source: str = "", query: str = "") -> dict[str, Any]:
|
|
242
260
|
"""评估 URL 的权威性(Selection 门槛)。
|
|
243
261
|
|
|
244
|
-
结果按 (url, source) 做进程内 lru_cache:同一 URL + source 组合在多次
|
|
262
|
+
结果按 (url, source, query) 做进程内 lru_cache:同一 URL + source 组合在多次
|
|
245
263
|
rerank/selection 中只算一次,避免 search.py 的 local_five_dim_rerank 与
|
|
246
264
|
_attach_selection_signals 对同一 URL 重复评分。
|
|
265
|
+
|
|
266
|
+
query 可选:只在有条件降权(demote_domains_unless,如裁判文书站)时需要,
|
|
267
|
+
无 query 的调用方保持原表行为,缓存也按空 query 各自命中。
|
|
247
268
|
"""
|
|
248
|
-
score, reason, tier, domain, is_serp = _score_authority_cached(url, source)
|
|
269
|
+
score, reason, tier, domain, is_serp = _score_authority_cached(url, source, query)
|
|
249
270
|
return {
|
|
250
271
|
"score": round(score, 2),
|
|
251
272
|
"reason": reason,
|
|
@@ -674,7 +695,7 @@ def compute_credibility(
|
|
|
674
695
|
title = r.get("title", "") or ""
|
|
675
696
|
snippet = r.get("snippet", "") or ""
|
|
676
697
|
|
|
677
|
-
auth = score_authority(url, source)
|
|
698
|
+
auth = score_authority(url, source, query)
|
|
678
699
|
fresh = score_freshness(r, query_time)
|
|
679
700
|
density = score_evidence_density(snippet, title)
|
|
680
701
|
|
package/scripts/local_seek.py
CHANGED
|
@@ -31,6 +31,26 @@ from typing import Any
|
|
|
31
31
|
# 本地命中是尾部增强项,不是主结果,它的等待不配与搜索引擎同等。
|
|
32
32
|
_LOCAL_SEEK_TIMEOUT_S = 3.0
|
|
33
33
|
|
|
34
|
+
# 搜索期告警(issue #34 第 4/7 条):--json 模式下 stderr 会被调用方
|
|
35
|
+
# 2>&1 合并,任何中文告警行都会破坏 JSON 解析。告警统一进这个列表,
|
|
36
|
+
# search.py 组装完响应后 drain 并作为 warnings[] 字段随 JSON 返回;
|
|
37
|
+
# 非 --json 调用保持写 stderr 的老行为(echo=True)。
|
|
38
|
+
_SEARCH_WARNINGS: list[str] = []
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _note_warning(msg: str, echo: bool = True) -> None:
|
|
42
|
+
"""记录一条搜索期告警;echo=True 时同时写 stderr(人读模式)。"""
|
|
43
|
+
_SEARCH_WARNINGS.append(msg)
|
|
44
|
+
if echo:
|
|
45
|
+
sys.stderr.write(msg + "\n")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def drain_search_warnings() -> list[str]:
|
|
49
|
+
"""取出并清空搜索期告警(search.py 在响应组装完后合并进 warnings[])。"""
|
|
50
|
+
out = _SEARCH_WARNINGS[:]
|
|
51
|
+
_SEARCH_WARNINGS.clear()
|
|
52
|
+
return out
|
|
53
|
+
|
|
34
54
|
# 「宽泛根」判定:这些目录**不能**当作本地检索范围。
|
|
35
55
|
# 跨平台补齐(2026-09-29):/mnt(WSL 挂载根)、/cygdrive(Cygwin)——
|
|
36
56
|
# 此前是 macOS 视角清单,Windows/WSL 的等价宽根漏网。
|
|
@@ -232,13 +252,17 @@ def _local_seek_dir() -> str | None:
|
|
|
232
252
|
|
|
233
253
|
def _run_local_seek(query: str, max_n: int = 5,
|
|
234
254
|
search_dir: str | None = None,
|
|
235
|
-
warn: bool = True) -> list[dict[str, Any]]:
|
|
255
|
+
warn: bool = True, echo: bool = True) -> list[dict[str, Any]]:
|
|
236
256
|
"""本机文件命中(include-local 用):进程内调 seek.run_query,JSON 并入。
|
|
237
257
|
|
|
238
258
|
fast/budget 模式下由 super_search 自动调用(_resolve_include_local),
|
|
239
259
|
auto/deep 需显式 --include-local / MCP include_local。评分与
|
|
240
260
|
MCP argo_local_search 同口径(0.9 精确 / 0.7 扩展)。
|
|
241
261
|
进程内失败回退子进程形态(_seek_query_subprocess),能力不回退。
|
|
262
|
+
|
|
263
|
+
echo=False 时告警不写 stderr,只进 drain_search_warnings()——`--json`
|
|
264
|
+
模式的调用方把 2>&1 合并成管道时,stderr 上的中文行会破坏 JSON 解析
|
|
265
|
+
(issue #34 第 7 条),告警改为结构化字段随响应返回。
|
|
242
266
|
"""
|
|
243
267
|
target = search_dir or _local_seek_dir()
|
|
244
268
|
if not target:
|
|
@@ -246,15 +270,16 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
246
270
|
# 「跳过」与「查了没有」在返回值上都是空列表,但含义完全不同——
|
|
247
271
|
# 静默跳过会让用户以为本地没匹配,而事实是根本没查。返回一个
|
|
248
272
|
# 占位「结果」又会污染 results(它只是个说明,不是命中),所以
|
|
249
|
-
#
|
|
273
|
+
# 说明走告警通道(stderr + 响应的 warnings[])。
|
|
250
274
|
# 只在**显式开启**时提示(warn=False 是 fast/budget 的自动路径):
|
|
251
275
|
# 自动路径在 home 等宽根下每次 search 都会打印,Agent 会把它当成
|
|
252
276
|
# 输出的一部分,属于噪音而非归因。
|
|
253
277
|
if warn:
|
|
254
|
-
|
|
278
|
+
_note_warning(
|
|
255
279
|
" [include-local] 当前目录不适合本地检索(home / 根目录过宽,或位于 argo "
|
|
256
280
|
"自身安装树内——只会命中自身源码),已跳过;"
|
|
257
|
-
"要搜本机文件请 cd 到目标目录后重试,或用 local-seek 的 seek.py --path
|
|
281
|
+
"要搜本机文件请 cd 到目标目录后重试,或用 local-seek 的 seek.py --path <目录>",
|
|
282
|
+
echo)
|
|
258
283
|
return []
|
|
259
284
|
|
|
260
285
|
# 缓存:同 query+target 在 TTL 内直接命中,避免重复冷启动 seek.py 子进程。
|
|
@@ -279,6 +304,13 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
279
304
|
from seek_locator import resolve_seek_py
|
|
280
305
|
seek_py = resolve_seek_py()
|
|
281
306
|
if not seek_py or not os.path.isfile(seek_py):
|
|
307
|
+
# issue #34 第 4 条:显式 --include-local 时 seek.py 找不到,此前静默
|
|
308
|
+
# 返回空列表,看起来与「本地没有匹配」一模一样。真正能定位的线索
|
|
309
|
+
# (装了 local-seek 子技能 / 设 ARGO_LOCAL_SEEK_PATH)必须说出来。
|
|
310
|
+
if warn:
|
|
311
|
+
_note_warning(
|
|
312
|
+
" [include-local] 未找到 local-seek 的 seek.py(装 local-seek 子技能,"
|
|
313
|
+
"或设 ARGO_LOCAL_SEEK_PATH 指向 seek.py);本机文件检索未执行", echo)
|
|
282
314
|
return []
|
|
283
315
|
|
|
284
316
|
# H2(2026-09-29):进程内直调 seek.run_query——省掉子进程解释器启动
|
|
@@ -289,12 +321,13 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
289
321
|
payload = None
|
|
290
322
|
try:
|
|
291
323
|
payload = seek_query_payload(query, target, max_n,
|
|
292
|
-
time_budget=_LOCAL_SEEK_TIMEOUT_S
|
|
324
|
+
time_budget=_LOCAL_SEEK_TIMEOUT_S,
|
|
325
|
+
warn=warn, echo=echo)
|
|
293
326
|
except Exception:
|
|
294
327
|
payload = None
|
|
295
328
|
if payload is None:
|
|
296
329
|
payload = _seek_query_subprocess(seek_py, query, target, max_n)
|
|
297
|
-
if payload is None:
|
|
330
|
+
if payload is None or payload.get("_error"):
|
|
298
331
|
return []
|
|
299
332
|
out = _payload_to_hits(payload, max_n, cache_key)
|
|
300
333
|
_seek_disk_cache_put(cache_key, out) # H3:写穿到落盘层
|
|
@@ -319,7 +352,8 @@ def _load_seek_module(seek_py: str):
|
|
|
319
352
|
|
|
320
353
|
|
|
321
354
|
def seek_query_payload(query: str, target: str, max_n: int,
|
|
322
|
-
exact: bool = False, time_budget: float | None = None
|
|
355
|
+
exact: bool = False, time_budget: float | None = None,
|
|
356
|
+
warn: bool = False, echo: bool = True
|
|
323
357
|
) -> dict[str, Any] | None:
|
|
324
358
|
"""H2 公共入口:进程内调 seek.run_query 取 JSON payload。
|
|
325
359
|
|
|
@@ -339,11 +373,19 @@ def seek_query_payload(query: str, target: str, max_n: int,
|
|
|
339
373
|
argv.append("--exact")
|
|
340
374
|
text, rc = mod.run_query(argv, time_budget=time_budget)
|
|
341
375
|
if rc != 0:
|
|
342
|
-
# rc=1
|
|
343
|
-
#
|
|
344
|
-
#
|
|
345
|
-
|
|
376
|
+
# rc=1 有两类:
|
|
377
|
+
# 1) 「未找到匹配」:seek.run_query 返回 "local-seek: 未找到匹配(...)"。
|
|
378
|
+
# 这是正常零命中,不是进程内异常——返回空结果避免子进程回退把同一搜索
|
|
379
|
+
# 再跑一遍(消除双跑税),并让 0 命中写入缓存。
|
|
380
|
+
# 2) 确定性环境/参数错误(如 Windows 缺 rg/grep、目录不存在):
|
|
381
|
+
# 子进程重跑结果完全一样;转为结构化告警并停止无意义回退(issue #34.4)。
|
|
382
|
+
stripped = text.strip()
|
|
383
|
+
if rc == 1 and (not stripped or "未找到匹配" in stripped):
|
|
346
384
|
return {"results": [], "total": 0}
|
|
385
|
+
if rc == 1 and stripped.startswith("local-seek:"):
|
|
386
|
+
if warn:
|
|
387
|
+
_note_warning(f" [include-local] {stripped}", echo)
|
|
388
|
+
return {"results": [], "total": 0, "_error": stripped}
|
|
347
389
|
return None
|
|
348
390
|
if not text.strip():
|
|
349
391
|
return None
|
package/scripts/mcp_transport.py
CHANGED