argo-search 2.14.0 → 2.14.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/AGENTS.md +1 -1
- package/README.es.md +18 -8
- package/README.ja.md +18 -8
- package/README.ko.md +18 -8
- package/README.md +511 -608
- package/README.zh.md +975 -0
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/backends/domain_profiles.json +24 -0
- package/backends/engine_registry.yaml +69 -18
- package/backends/quota_profiles.json +40 -0
- package/config.yaml +23 -3
- package/docs/CHANGELOG.md +22 -0
- package/docs/ENGINE_CATALOG.md +41 -37
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.14.0.md +12 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
- package/docs/RELEASING.md +52 -0
- package/engines/specs/artic.yaml +11 -1
- package/engines/specs/cleveland.yaml +15 -1
- package/engines/specs/clinicaltrials.yaml +16 -1
- package/engines/specs/cnii.yaml +15 -4
- package/engines/specs/deezer.yaml +12 -1
- package/engines/specs/doaj.yaml +14 -1
- package/engines/specs/endoflife.yaml +16 -1
- package/engines/specs/eu_opendata.yaml +11 -1
- package/engines/specs/europeana.yaml +19 -1
- package/engines/specs/feed.yaml +62 -0
- package/engines/specs/figshare.yaml +12 -1
- package/engines/specs/hackernews.yaml +17 -2
- package/engines/specs/hal.yaml +19 -1
- package/engines/specs/hf_datasets.yaml +59 -0
- package/engines/specs/hf_papers.yaml +17 -1
- package/engines/specs/jikan.yaml +12 -10
- package/engines/specs/kaggle.yaml +5 -3
- package/engines/specs/maven.yaml +61 -0
- package/engines/specs/nasa_cmr.yaml +12 -1
- package/engines/specs/nuget.yaml +57 -0
- package/engines/specs/tatoeba.yaml +14 -1
- package/engines/specs/tvmaze.yaml +5 -1
- package/engines/specs/usda.yaml +14 -1
- package/package.json +2 -1
- package/packages/dsh-plugin/dsh/native-tools.mjs +61 -113
- package/packages/dsh-plugin/dsh/wide-research.js +1 -1
- package/packages/dsh-plugin/package.json +1 -1
- package/scripts/badcase_ledger.py +49 -5
- package/scripts/build_release_assets.sh +43 -15
- package/scripts/dormant_ledger.py +225 -0
- package/scripts/engine_states.py +6 -1
- package/scripts/engine_validate.py +182 -6
- package/scripts/engines.py +0 -36
- package/scripts/engines_base.py +27 -67
- package/scripts/engines_builders.py +0 -36
- package/scripts/engines_builders_batch16.py +6 -179
- package/scripts/engines_builders_batch9.py +0 -204
- package/scripts/engines_builders_feeds.py +148 -30
- package/scripts/engines_builders_intl.py +0 -328
- package/scripts/engines_builders_science.py +0 -85
- package/scripts/engines_builders_tech.py +0 -98
- package/scripts/engines_parsers.py +534 -9
- package/scripts/evidence_loop.py +91 -4
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/gen_native_tools.py +2 -1
- package/scripts/local_intent.py +51 -15
- package/scripts/local_seek.py +37 -4
- package/scripts/mcp_handlers.py +124 -72
- package/scripts/mcp_server.py +1 -1
- package/scripts/mcp_tools.py +143 -61
- package/scripts/mcp_transport.py +42 -10
- package/scripts/pre-commit +25 -1
- package/scripts/release.py +20 -11
- package/scripts/release_check.py +1 -1
- package/scripts/route_policy.py +6 -1
- package/scripts/search_cli.py +44 -7
- package/scripts/secret_guard.py +106 -0
- package/scripts/semantic_evidence.py +230 -15
- package/scripts/settings_page.py +80 -8
- package/scripts/source_audit.py +77 -0
- package/scripts/sync_backends.py +7 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +9 -1
- package/README.en.md +0 -826
- package/scripts/image_vision/vision_probe +0 -0
package/scripts/evidence_loop.py
CHANGED
|
@@ -583,9 +583,37 @@ def verify_results(results: list[dict[str, Any]],
|
|
|
583
583
|
semantic_meta: dict[str, Any] | None = None
|
|
584
584
|
if scored_inputs:
|
|
585
585
|
try:
|
|
586
|
-
from semantic_evidence import
|
|
586
|
+
from semantic_evidence import (
|
|
587
|
+
assess_support, assess_source_types,
|
|
588
|
+
assess_substantive_discussion, enabled as _semantic_enabled,
|
|
589
|
+
)
|
|
587
590
|
if _semantic_enabled():
|
|
588
591
|
support = assess_support(query, scored_inputs)
|
|
592
|
+
source_types = assess_source_types(scored_inputs)
|
|
593
|
+
substantive_map = assess_substantive_discussion(query, scored_inputs)
|
|
594
|
+
primary_count = 0
|
|
595
|
+
substantive_count = 0
|
|
596
|
+
passing_count = 0
|
|
597
|
+
# 加权必须同时写回 results 原始行:verified 是 _record_verify
|
|
598
|
+
# 新建的展示副本,而下游 reorder_by_evidence 读的是
|
|
599
|
+
# r["post_fetch_absorption"](原始行),只读副本的 +0.20/+0.15
|
|
600
|
+
# 不会改变任何排序分(2026-11-11 审计)。按 URL 定位,避免
|
|
601
|
+
# 再引入第二份顺序假设。
|
|
602
|
+
result_by_url = {r.get("url") or "": r for r in results}
|
|
603
|
+
|
|
604
|
+
def _apply_adjustment(url: str, delta: float) -> None:
|
|
605
|
+
row = result_by_url.get(url)
|
|
606
|
+
if row is None:
|
|
607
|
+
return
|
|
608
|
+
base = row.get("post_fetch_absorption")
|
|
609
|
+
if base is None:
|
|
610
|
+
base = row.get("absorption") or 0.0
|
|
611
|
+
try:
|
|
612
|
+
adjusted = max(0.0, min(1.0, float(base) + delta))
|
|
613
|
+
except (TypeError, ValueError):
|
|
614
|
+
return
|
|
615
|
+
row["post_fetch_absorption"] = round(adjusted, 3)
|
|
616
|
+
|
|
589
617
|
if support:
|
|
590
618
|
for item in verified:
|
|
591
619
|
info = support.get(item.get("url") or "")
|
|
@@ -595,11 +623,70 @@ def verify_results(results: list[dict[str, Any]],
|
|
|
595
623
|
info = support.get(r.get("url") or "")
|
|
596
624
|
if info:
|
|
597
625
|
r["semantic_support"] = info
|
|
626
|
+
if source_types:
|
|
627
|
+
for item in verified:
|
|
628
|
+
st = source_types.get(item.get("url") or "")
|
|
629
|
+
if st:
|
|
630
|
+
item["source_type"] = st
|
|
631
|
+
if st.get("is_primary"):
|
|
632
|
+
primary_count += 1
|
|
633
|
+
# 官方一手源加权置顶:absorption 基础分提权 0.20
|
|
634
|
+
item["post_absorption"] = min(1.0, (item.get("post_absorption") or 0.0) + 0.20)
|
|
635
|
+
if "delta" in item:
|
|
636
|
+
item["delta"] = round(item["post_absorption"] - (item.get("pre_absorption") or 0.0), 3)
|
|
637
|
+
_apply_adjustment(item.get("url") or "", 0.20)
|
|
638
|
+
for r in results:
|
|
639
|
+
st = source_types.get(r.get("url") or "")
|
|
640
|
+
if st:
|
|
641
|
+
r["source_type"] = st
|
|
642
|
+
if substantive_map:
|
|
643
|
+
for item in verified:
|
|
644
|
+
sub = substantive_map.get(item.get("url") or "")
|
|
645
|
+
if sub:
|
|
646
|
+
item["discussion_depth"] = sub
|
|
647
|
+
if sub.get("is_substantive"):
|
|
648
|
+
substantive_count += 1
|
|
649
|
+
item["substantive_discussion"] = True
|
|
650
|
+
# 深度实质探讨加权提权:+0.15
|
|
651
|
+
item["post_absorption"] = min(1.0, (item.get("post_absorption") or 0.0) + 0.15)
|
|
652
|
+
if "delta" in item:
|
|
653
|
+
item["delta"] = round(item["post_absorption"] - (item.get("pre_absorption") or 0.0), 3)
|
|
654
|
+
_apply_adjustment(item.get("url") or "", 0.15)
|
|
655
|
+
elif sub.get("is_passing_mention"):
|
|
656
|
+
passing_count += 1
|
|
657
|
+
item["passing_mention"] = True
|
|
658
|
+
# 仅顺带提及闲聊降权去噪:-0.10
|
|
659
|
+
item["post_absorption"] = max(0.0, (item.get("post_absorption") or 0.0) - 0.10)
|
|
660
|
+
if "delta" in item:
|
|
661
|
+
item["delta"] = round(item["post_absorption"] - (item.get("pre_absorption") or 0.0), 3)
|
|
662
|
+
_apply_adjustment(item.get("url") or "", -0.10)
|
|
663
|
+
for r in results:
|
|
664
|
+
sub = substantive_map.get(r.get("url") or "")
|
|
665
|
+
if sub:
|
|
666
|
+
r["discussion_depth"] = sub
|
|
667
|
+
if sub.get("is_substantive"):
|
|
668
|
+
r["substantive_discussion"] = True
|
|
669
|
+
elif sub.get("is_passing_mention"):
|
|
670
|
+
r["passing_mention"] = True
|
|
671
|
+
|
|
672
|
+
if any((primary_count, substantive_count, passing_count)):
|
|
673
|
+
revisions = [v["delta"] for v in verified if "delta" in v]
|
|
674
|
+
|
|
675
|
+
if support or source_types or substantive_map:
|
|
676
|
+
c_count = sum(1 for x in (support or {}).values() if x.get("contradicts"))
|
|
598
677
|
semantic_meta = {
|
|
599
|
-
"scored": len(support),
|
|
600
|
-
"supports": sum(1 for x in support.values() if x
|
|
601
|
-
"contradicts":
|
|
678
|
+
"scored": len(support or source_types or substantive_map or {}),
|
|
679
|
+
"supports": sum(1 for x in (support or {}).values() if x.get("supports")),
|
|
680
|
+
"contradicts": c_count,
|
|
681
|
+
"primary_sources": primary_count,
|
|
682
|
+
"substantive_discussions": substantive_count,
|
|
683
|
+
"passing_mentions": passing_count,
|
|
602
684
|
}
|
|
685
|
+
if c_count > 0:
|
|
686
|
+
semantic_meta["contradiction_alert"] = True
|
|
687
|
+
semantic_meta["contradiction_warning"] = (
|
|
688
|
+
f"检测到权威信源反驳当前查询前提({c_count} 条条目与主张冲突)"
|
|
689
|
+
)
|
|
603
690
|
except Exception as e: # fail-open:语义层不阻断核验
|
|
604
691
|
_log(f"语义证据层失败: {type(e).__name__}")
|
|
605
692
|
|
|
@@ -351,14 +351,14 @@ def _names(rows: list[dict[str, Any]]) -> str:
|
|
|
351
351
|
# 10-20 个文件;改为单点后正文只写「数百个源」这类不随引擎增减而变的说法。
|
|
352
352
|
# 版本号与工具数仍按句模板校正:它们变化少,且徽章、包描述需要精确值。
|
|
353
353
|
COUNT_RULES: dict[str, list[tuple[str, str]]] = {
|
|
354
|
-
'README.md': [
|
|
354
|
+
'README.zh.md': [
|
|
355
355
|
('badge/version-(?P<version>[\\d.]+)-informational', 'badge/version-{version}-informational'),
|
|
356
356
|
('badge/MCP-(?P<tools>\\d+)%20tools-purple', 'badge/MCP-{tools}%20tools-purple'),
|
|
357
357
|
('另有 1 个 `wide_research` 并行研究和 (?P<tools>\\d+) 个 MCP 工具按需开启', '另有 1 个 `wide_research` 并行研究和 {tools} 个 MCP 工具按需开启'),
|
|
358
358
|
('其余 (?P<n>\\d+) 个源不受影响', '其余源不受影响'),
|
|
359
359
|
('搜索、抓取、核验、本机文件检索走同一条管线,(?P<tools>\\d+) 个 MCP 工具和 CLI 命令一一对应', '搜索、抓取、核验、本机文件检索走同一条管线,{tools} 个 MCP 工具和 CLI 命令一一对应'),
|
|
360
360
|
],
|
|
361
|
-
'README.
|
|
361
|
+
'README.md': [
|
|
362
362
|
('badge/version-(?P<version>[\\d.]+)-informational', 'badge/version-{version}-informational'),
|
|
363
363
|
('badge/MCP-(?P<tools>\\d+)%20tools-purple', 'badge/MCP-{tools}%20tools-purple'),
|
|
364
364
|
('and (?P<tools>\\d+) MCP tools you can enable on demand', 'and {tools} MCP tools you can enable on demand'),
|
|
@@ -31,7 +31,7 @@ SCRIPT_DIR = Path(__file__).resolve().parent
|
|
|
31
31
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
32
32
|
|
|
33
33
|
import engine_states # noqa: E402
|
|
34
|
-
from mcp_tools import TOOLS # noqa: E402
|
|
34
|
+
from mcp_tools import TOOLS, sanitize_tool # noqa: E402
|
|
35
35
|
|
|
36
36
|
OUT_PATH = SCRIPT_DIR.parent / "packages" / "dsh-plugin" / "dsh" / "native-tools.mjs"
|
|
37
37
|
|
|
@@ -57,6 +57,7 @@ HEADER = """\
|
|
|
57
57
|
def build_native_tools() -> dict:
|
|
58
58
|
out: dict[str, dict] = {}
|
|
59
59
|
for tool in TOOLS:
|
|
60
|
+
tool = sanitize_tool(tool)
|
|
60
61
|
name = tool["name"]
|
|
61
62
|
if name in _EXCLUDED:
|
|
62
63
|
continue
|
package/scripts/local_intent.py
CHANGED
|
@@ -26,9 +26,12 @@ _LOCAL_SIGNAL_RE = re.compile(
|
|
|
26
26
|
r"(?i)(?:\b(?:def|class|function|fn|import|export|const|var|struct|enum)\b|"
|
|
27
27
|
r"\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|sql|conf|cfg|ini|log)\b|"
|
|
28
28
|
r"(?:readme|config|package\.json|cargo\.toml|dockerfile|makefile|pyproject\.toml|tsconfig\.json|go\.mod|requirements\.txt|Cargo\.lock|\.gitignore|\.env)|"
|
|
29
|
-
|
|
29
|
+
# 异常类:Error/Exception/Fault 是编程词;Warning 限定为编程常见警告类
|
|
30
|
+
# (气象/日常预警词如 StormWarning/FloodWarning 不算——bffdaf6 只改了强
|
|
31
|
+
# 信号正则,弱信号路径仍会让「StormWarning 发布」在中文语境下空跑本机轨)。
|
|
32
|
+
r"\b[A-Za-z0-9_]+(?:Error|Exception|Fault)\b|\b(?:User|Deprecation|Runtime|Future|Syntax|Resource|Import)Warning\b|"
|
|
30
33
|
r"\b_[a-zA-Z0-9_]{2,}\b|"
|
|
31
|
-
r"\b[a-zA-Z0-9_]
|
|
34
|
+
r"\b[a-zA-Z_][a-zA-Z0-9_]*\((?!\s*(?:[0-9]+|[a-zA-Z])\s*\))[^\)]*\)|"
|
|
32
35
|
r"(?:本工程|本项目|代码库|本地文件|本地脚本|脚本文件|架构实现|函数|方法|源码|接口定义|"
|
|
33
36
|
# 2026-11-10 P0-1 补:实测「我的 .agents/skills 有哪些」「我的文件」
|
|
34
37
|
# 「仓库里」「本机」这类说法在默认路径下被误判为公网查询,漏搜本机。
|
|
@@ -91,20 +94,51 @@ def should_skip_local(domain: str | None, query: str) -> bool:
|
|
|
91
94
|
# 新判据把默认翻转为信号驱动:**只有查询明确带本地意图才跑本机轨**。
|
|
92
95
|
# 判据失败 fail-open(宁可多搜也不误杀)——见 should_run_local_by_signal。
|
|
93
96
|
|
|
94
|
-
#
|
|
95
|
-
|
|
97
|
+
# 强本地意图信号:路径前缀、文件扩展名、工程文件、中文本地说法、本机目录,
|
|
98
|
+
# 以及异常类/私有标识符/函数调用这类**不可能出现在公域答案里**的代码特征。
|
|
99
|
+
#
|
|
100
|
+
# 为什么与 _LOCAL_SIGNAL_RE 分开(2026-11-10 修复):两者语义不同——
|
|
101
|
+
# _LOCAL_SIGNAL_RE 含 def/class/import 等**泛代码词**("import" 会出现在
|
|
102
|
+
# 「import 天气预报接口」这种半技术半公域的查询里),是弱信号,需配合中文语境;
|
|
103
|
+
# 强信号命中即跑,且**优先于公域守卫**(`_run_local_seek 在哪` 即使在天气域,
|
|
104
|
+
# 也是明确的本地代码检索,本机结果不是噪声)。
|
|
105
|
+
# 曾把 _STRONG_LOCAL_SIGNAL_RE 直接赋值为 _LOCAL_SIGNAL_RE 求「单一真源」,
|
|
106
|
+
# 结果公域守卫失效:泛代码词被当成强信号,`import 天气预报接口` 在
|
|
107
|
+
# weather_query 域下空跑(实测 True,设计意图 False)。
|
|
108
|
+
_STRONG_LOCAL_SIGNAL_RE = re.compile(
|
|
109
|
+
r"(?i)(?:"
|
|
110
|
+
# 路径前缀(最明确)
|
|
111
|
+
r"(?:^|[\s\"'`(])(?:~/|/Users/|/home/|file://|C:\\\\|\./|\.\./)|"
|
|
112
|
+
# 文件扩展名
|
|
113
|
+
r"\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|"
|
|
114
|
+
r"sql|docx|pptx|xlsx|pdf|csv|log|cfg|ini|conf)\b|"
|
|
115
|
+
# 工程/配置文件名
|
|
116
|
+
r"(?:readme|package\.json|cargo\.toml|dockerfile|makefile|"
|
|
117
|
+
r"\.gitignore|\.env|pyproject\.toml|tsconfig\.json|"
|
|
118
|
+
r"go\.mod|requirements\.txt|Cargo\.lock)|"
|
|
119
|
+
# 异常类与错误类名(公域答案里不会出现;Warning 限定为编程常见警告类,排除气象与日常预警词)
|
|
120
|
+
r"\b[A-Za-z0-9_]+(?:Error|Exception|Fault)\b|\b(?:User|Deprecation|Runtime|Future|Syntax|Resource|Import)Warning\b|"
|
|
121
|
+
# 私有标识符(下划线开头,公域答案里不会出现)
|
|
122
|
+
r"\b_[a-zA-Z0-9_]{2,}\b|"
|
|
123
|
+
# 函数调用特征(`foo(...)`,排除 (19)/(D)/(x) 等纯数字或单字母变量与公域缩写)
|
|
124
|
+
r"\b[a-zA-Z_][a-zA-Z0-9_]*\((?!\s*(?:[0-9]+|[a-zA-Z])\s*\))[^\)]*\)|"
|
|
125
|
+
# 本机目录与说法
|
|
126
|
+
r"(?:\.agents/skills|\.obsidian|\.config/argo|本机|本地文件|本地脚本|"
|
|
127
|
+
r"本地代码|本地笔记|我的文件|我的笔记|我的电脑|我的代码|代码库|本工程|本项目|"
|
|
128
|
+
r"这个仓库|这个工程|当前目录|工作目录|源码里|仓库里|仓库中|工程里|项目里)"
|
|
129
|
+
r")"
|
|
130
|
+
)
|
|
96
131
|
|
|
97
132
|
|
|
98
133
|
def has_strong_local_signal(query: str) -> bool:
|
|
99
|
-
"""
|
|
134
|
+
"""查询是否带**强**本地意图信号(命中即跑,优先于公域守卫)。
|
|
100
135
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
且覆盖异常类、私有符号、扩展名、工程文件、中文本地说法。重写一份必然引入漂移。
|
|
136
|
+
不含 def/class/import/function 等泛代码词——那些是弱信号,需配合中文语境
|
|
137
|
+
才成立(「def cache_key 怎么实现的」跑,「python asyncio error handling」不跑)。
|
|
104
138
|
"""
|
|
105
139
|
if not query:
|
|
106
140
|
return False
|
|
107
|
-
return
|
|
141
|
+
return bool(_STRONG_LOCAL_SIGNAL_RE.search(query))
|
|
108
142
|
|
|
109
143
|
|
|
110
144
|
def should_run_local_by_signal(query: str, domain: str | None = None) -> bool:
|
|
@@ -116,17 +150,19 @@ def should_run_local_by_signal(query: str, domain: str | None = None) -> bool:
|
|
|
116
150
|
- should_run_local_by_signal:默认路径的主判据(无域信息时靠它)。
|
|
117
151
|
|
|
118
152
|
判据(两层信号,任一命中即跑):
|
|
119
|
-
1.
|
|
120
|
-
|
|
121
|
-
|
|
153
|
+
1. 强信号:路径前缀、文件扩展名、工程文件、异常类、私有标识符、
|
|
154
|
+
函数调用、中文本地说法——命中即跑,**优先于公域守卫**
|
|
155
|
+
(`_run_local_seek 在哪` 即使在天气域也是本地代码检索);
|
|
156
|
+
2. 弱信号 + 中文:泛代码词(def/class/fn/import)+ 中文语境
|
|
157
|
+
——「def cache_key 怎么实现的」是明确的本地代码检索意图,
|
|
122
158
|
但纯英文「python asyncio error handling」不是。
|
|
123
159
|
|
|
124
|
-
|
|
125
|
-
|
|
160
|
+
公域答案型域(天气/汇率等)只在**弱信号**路径生效:无强信号时,即使
|
|
161
|
+
带泛代码词也不跑——「import 天气预报接口」的本机结果必然是噪声。
|
|
126
162
|
"""
|
|
127
163
|
if has_strong_local_signal(query):
|
|
128
164
|
return True
|
|
129
|
-
#
|
|
165
|
+
# 公域守卫:只拦弱信号路径(强信号已在上面返回)
|
|
130
166
|
if domain and domain in _PUBLIC_ONLY_DOMAINS:
|
|
131
167
|
return False
|
|
132
168
|
if has_local_signal(query) and _has_cjk(query):
|
package/scripts/local_seek.py
CHANGED
|
@@ -218,7 +218,7 @@ def _seek_disk_cache_put(key: str, results: list[dict[str, Any]]) -> None:
|
|
|
218
218
|
# 判据与 local_intent._LOCAL_SIGNAL_RE 逐字一致(红绿锁见
|
|
219
219
|
# tests/test_local_intent.py::test_intent_pattern_matches_local_seek)。
|
|
220
220
|
_LOCAL_INTENT_PATTERN = re.compile(
|
|
221
|
-
'(?i)(
|
|
221
|
+
r'(?i)(?:\b(?:def|class|function|fn|import|export|const|var|struct|enum)\b|\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|sql|conf|cfg|ini|log)\b|(?:readme|config|package\.json|cargo\.toml|dockerfile|makefile|pyproject\.toml|tsconfig\.json|go\.mod|requirements\.txt|Cargo\.lock|\.gitignore|\.env)|\b[A-Za-z0-9_]+(?:Error|Exception|Fault)\b|\b(?:User|Deprecation|Runtime|Future|Syntax|Resource|Import)Warning\b|\b_[a-zA-Z0-9_]{2,}\b|\b[a-zA-Z_][a-zA-Z0-9_]*\((?!\s*(?:[0-9]+|[a-zA-Z])\s*\))[^\)]*\)|(?:本工程|本项目|代码库|本地文件|本地脚本|脚本文件|架构实现|函数|方法|源码|接口定义|本机|本地代码|本地笔记|我的文件|我的笔记|我的电脑|我的代码|仓库里|仓库中|工程里|项目里|当前目录|工作目录|\.agents/skills|\.obsidian))')
|
|
222
222
|
|
|
223
223
|
|
|
224
224
|
def has_local_code_intent(query: str) -> bool:
|
|
@@ -317,16 +317,40 @@ def _local_seek_dir() -> str | None:
|
|
|
317
317
|
return _detect_project_root(cwd) or cwd
|
|
318
318
|
|
|
319
319
|
|
|
320
|
+
_CACHED_TARGETED_ROOTS: tuple[tuple[str, ...], float, list[str]] | None = None
|
|
321
|
+
# 缓存有效期(秒)。为什么需要 TTL:缓存键只含环境变量,不含文件系统状态——
|
|
322
|
+
# 进程内新建 ~/notes 这类标准根时,无 TTL 的缓存会让新目录在整个进程生命
|
|
323
|
+
# 周期内都不可见(实测)。60s 是「同一轮检索内不重复探测」与「新目录能较快
|
|
324
|
+
# 生效」的折中:检索是多目标串行的,单轮耗时远小于 60s,跨轮则能感知变化。
|
|
325
|
+
_TARGETED_ROOTS_CACHE_TTL_S = 60.0
|
|
326
|
+
|
|
327
|
+
|
|
320
328
|
def _candidate_targeted_roots() -> list[str]:
|
|
321
329
|
"""宽泛根场景下的定向检索候选目录(既防全盘扫崩,又避免漏掉核心私域资产)。
|
|
322
330
|
|
|
323
331
|
彻底消除特定机器/个人工作区硬编码(如 Documents/GPT),优先环境变量覆盖,
|
|
324
332
|
自适应感知云端/容器工作区与跨平台 Agent 技能规范。
|
|
333
|
+
带环境变量感知与 TTL 的轻量缓存,消除每轮检索重复的文件系统 isdir/realpath
|
|
334
|
+
探测,同时不把新建目录锁死在进程生命周期内。
|
|
325
335
|
"""
|
|
326
|
-
|
|
336
|
+
global _CACHED_TARGETED_ROOTS
|
|
337
|
+
env_key = (
|
|
338
|
+
os.environ.get("ARGO_LOCAL_SEEK_ROOTS", ""),
|
|
339
|
+
os.environ.get("WORKSPACE", ""),
|
|
340
|
+
os.environ.get("PROJECT_DIR", ""),
|
|
341
|
+
os.environ.get("CI_PROJECT_DIR", ""),
|
|
342
|
+
)
|
|
343
|
+
if (_CACHED_TARGETED_ROOTS is not None
|
|
344
|
+
and _CACHED_TARGETED_ROOTS[0] == env_key
|
|
345
|
+
and time.time() - _CACHED_TARGETED_ROOTS[1] < _TARGETED_ROOTS_CACHE_TTL_S):
|
|
346
|
+
return list(_CACHED_TARGETED_ROOTS[2])
|
|
347
|
+
|
|
348
|
+
raw = env_key[0].strip()
|
|
327
349
|
if raw:
|
|
328
350
|
cands = [p for p in re.split(r"[:;]", raw) if p.strip()]
|
|
329
|
-
|
|
351
|
+
valid_roots = [c for c in cands if os.path.isdir(c) and not _is_own_install_root(c) and not _is_broad_local_root(c)]
|
|
352
|
+
_CACHED_TARGETED_ROOTS = (env_key, time.time(), list(valid_roots))
|
|
353
|
+
return valid_roots
|
|
330
354
|
|
|
331
355
|
cands: list[str] = []
|
|
332
356
|
|
|
@@ -363,6 +387,7 @@ def _candidate_targeted_roots() -> list[str]:
|
|
|
363
387
|
seen.add(real_c)
|
|
364
388
|
if os.path.isdir(real_c) and not _is_broad_local_root(real_c) and not _is_own_install_root(real_c):
|
|
365
389
|
valid_roots.append(real_c)
|
|
390
|
+
_CACHED_TARGETED_ROOTS = (env_key, time.time(), list(valid_roots))
|
|
366
391
|
return valid_roots
|
|
367
392
|
|
|
368
393
|
|
|
@@ -380,6 +405,7 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
380
405
|
_t0 = time.time()
|
|
381
406
|
_LAST_LOCAL_SEEK_SKIPPED = False
|
|
382
407
|
target = search_dir or _local_seek_dir()
|
|
408
|
+
is_targeted_fallback = not target
|
|
383
409
|
targets = [target] if target else _candidate_targeted_roots()
|
|
384
410
|
if not targets:
|
|
385
411
|
_LAST_LOCAL_SEEK_SKIPPED = True
|
|
@@ -404,7 +430,12 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
404
430
|
seen_urls: set[str] = set()
|
|
405
431
|
_cap = min(max_n, _max_local_hits())
|
|
406
432
|
|
|
433
|
+
# 宽泛根定向私域回退时的总体时间预算(0.35s),防止多目标串行拖累整次搜索
|
|
434
|
+
_targeted_deadline = (_t0 + 0.35) if is_targeted_fallback else None
|
|
435
|
+
|
|
407
436
|
for tgt in targets:
|
|
437
|
+
if _targeted_deadline and time.time() >= _targeted_deadline:
|
|
438
|
+
break
|
|
408
439
|
cache_key = f"{query}|{max_n}|{tgt}"
|
|
409
440
|
cached = _LOCAL_SEEK_CACHE.get(cache_key)
|
|
410
441
|
if cached is not None and time.time() - cached[0] < _LOCAL_SEEK_TTL_S:
|
|
@@ -422,9 +453,11 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
422
453
|
# 不在这里 return——多目标场景下其余目标可能仍有缓存。
|
|
423
454
|
continue
|
|
424
455
|
payload = None
|
|
456
|
+
_budget = (min(_LOCAL_SEEK_TIMEOUT_S, max(0.1, _targeted_deadline - time.time()))
|
|
457
|
+
if _targeted_deadline else _LOCAL_SEEK_TIMEOUT_S)
|
|
425
458
|
try:
|
|
426
459
|
payload = seek_query_payload(query, tgt, max_n,
|
|
427
|
-
time_budget=
|
|
460
|
+
time_budget=_budget,
|
|
428
461
|
warn=warn, echo=echo)
|
|
429
462
|
except Exception:
|
|
430
463
|
payload = None
|
package/scripts/mcp_handlers.py
CHANGED
|
@@ -99,6 +99,21 @@ def _err_is(message: str) -> dict[str, Any]:
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
def _ok(payload: Any, pretty: bool = False) -> dict[str, Any]:
|
|
102
|
+
"""所有 MCP 工具返回的唯一出口。
|
|
103
|
+
|
|
104
|
+
脱敏必须挂在这里,不能挂在各工具分支:分支有 19 个,漏一个就是一条
|
|
105
|
+
「凭据经 MCP 反射给 Agent 与 LLM」的通道,而漏了不会有任何信号。
|
|
106
|
+
入口处的 CLI 侧(search_cli)另有一处,是历史形态,不是本函数的理由。
|
|
107
|
+
|
|
108
|
+
代价实测(2026-11-11,本机):get_active_secrets 0.07ms/次 +
|
|
109
|
+
redact_data(5 条结果) 0.43ms/次,相对搜索本身 78~82ms 是 0.6%,
|
|
110
|
+
相对深度研究分钟级是零头。
|
|
111
|
+
"""
|
|
112
|
+
try:
|
|
113
|
+
from secret_guard import redact_data
|
|
114
|
+
payload = redact_data(payload)
|
|
115
|
+
except Exception:
|
|
116
|
+
pass
|
|
102
117
|
return {"content": [{"type": "text", "text": _dumps(payload, pretty=pretty)}]}
|
|
103
118
|
|
|
104
119
|
|
|
@@ -194,7 +209,81 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
|
194
209
|
"isError": True,
|
|
195
210
|
}
|
|
196
211
|
|
|
212
|
+
# 兼容旧工具调用的软别名映射(向后兼容):
|
|
213
|
+
if name == "argo_social_search":
|
|
214
|
+
args = dict(arguments)
|
|
215
|
+
args["domain"] = "social"
|
|
216
|
+
return execute_tool("argo_search", args)
|
|
217
|
+
elif name == "argo_job":
|
|
218
|
+
args = dict(arguments)
|
|
219
|
+
args["domain"] = "job"
|
|
220
|
+
return execute_tool("argo_search", args)
|
|
221
|
+
elif name == "argo_pdf":
|
|
222
|
+
args = dict(arguments)
|
|
223
|
+
args["mode"] = "pdf"
|
|
224
|
+
return execute_tool("argo_fetch", args)
|
|
225
|
+
elif name == "argo_article":
|
|
226
|
+
args = dict(arguments)
|
|
227
|
+
args["mode"] = "article"
|
|
228
|
+
return execute_tool("argo_fetch", args)
|
|
229
|
+
|
|
197
230
|
if name == "argo_search":
|
|
231
|
+
domain = arguments.get("domain", "web")
|
|
232
|
+
if domain == "social":
|
|
233
|
+
# 旧工具名 argo_social_search 的专属参数在这里仍要认(软别名
|
|
234
|
+
# 只补了 domain,platforms/mode/max_results 原样进来):
|
|
235
|
+
# platforms → 平台名单(默认 hackernews,zhihu,bilibili)
|
|
236
|
+
# mode → text | sentiment(旧名直接给值,不叫 social-sentiment)
|
|
237
|
+
# max_results→ 每平台条数(旧名 num 也认)
|
|
238
|
+
# 漏读任何一个,旧调用方的参数都会静默退化成默认值——调用成功、
|
|
239
|
+
# 结果不是他要的那批,没有任何信号。
|
|
240
|
+
platforms_str = arguments.get("platforms", "hackernews,zhihu,bilibili")
|
|
241
|
+
platforms = [p.strip() for p in platforms_str.split(",") if p.strip()]
|
|
242
|
+
query = arguments["query"]
|
|
243
|
+
n = _clamp_int(
|
|
244
|
+
arguments.get("max_results", arguments.get("num", 5)), 5, 1, 20)
|
|
245
|
+
platform_results, engines_used, errors = _search_social_platforms(platforms, query, n)
|
|
246
|
+
if str(arguments.get("mode", "text")).strip().lower() in (
|
|
247
|
+
"sentiment", "social-sentiment"):
|
|
248
|
+
research_mod = _lazy_cached("research")
|
|
249
|
+
output = research_mod.aggregate_social_sentiment(
|
|
250
|
+
query=query, platforms=platforms, platform_results=platform_results,
|
|
251
|
+
)
|
|
252
|
+
else:
|
|
253
|
+
all_results: list = []
|
|
254
|
+
for p in platforms:
|
|
255
|
+
all_results.extend(platform_results.get(p) or [])
|
|
256
|
+
output = {
|
|
257
|
+
"query": query,
|
|
258
|
+
"platforms": platforms,
|
|
259
|
+
"results": all_results,
|
|
260
|
+
"count": len(all_results),
|
|
261
|
+
"engines_used": engines_used,
|
|
262
|
+
}
|
|
263
|
+
if errors:
|
|
264
|
+
output["errors"] = errors
|
|
265
|
+
return _ok(output, pretty=pretty)
|
|
266
|
+
elif domain == "job":
|
|
267
|
+
job_mod = _lazy_cached("job")
|
|
268
|
+
try:
|
|
269
|
+
out = job_mod.search(
|
|
270
|
+
arguments["query"],
|
|
271
|
+
city=arguments.get("city", ""),
|
|
272
|
+
num=_clamp_int(arguments.get("max_results", arguments.get("num", 5)), 5, 1, 20),
|
|
273
|
+
platforms=arguments.get("platforms", ""),
|
|
274
|
+
loose=bool(arguments.get("loose", False)),
|
|
275
|
+
fetch_n=_clamp_int(arguments.get("fetch_detail", 0), 0, 0, 10),
|
|
276
|
+
)
|
|
277
|
+
except ValueError as e:
|
|
278
|
+
return {"content": [{"type": "text", "text": _dumps({"error": str(e)})}],
|
|
279
|
+
"isError": True}
|
|
280
|
+
return _ok(out, pretty=pretty)
|
|
281
|
+
elif domain == "local":
|
|
282
|
+
return handle_local_search(
|
|
283
|
+
arguments, pretty=pretty, ok_fn=_ok,
|
|
284
|
+
clamp_int_fn=_clamp_int, lazy_cached_fn=_lazy_cached,
|
|
285
|
+
)
|
|
286
|
+
|
|
198
287
|
search_mod = _lazy_cached("search")
|
|
199
288
|
result = search_mod.super_search(
|
|
200
289
|
query=arguments["query"],
|
|
@@ -282,32 +371,6 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
|
282
371
|
payload = result
|
|
283
372
|
return _ok(payload, pretty=pretty)
|
|
284
373
|
|
|
285
|
-
elif name == "argo_social_search":
|
|
286
|
-
platforms_str = arguments.get("platforms", "hackernews,zhihu,bilibili")
|
|
287
|
-
platforms = [p.strip() for p in platforms_str.split(",") if p.strip()]
|
|
288
|
-
query = arguments["query"]
|
|
289
|
-
n = _clamp_int(arguments.get("max_results", 5), 5, 1, 20)
|
|
290
|
-
platform_results, engines_used, errors = _search_social_platforms(platforms, query, n)
|
|
291
|
-
if arguments.get("mode", "text") == "sentiment":
|
|
292
|
-
research_mod = _lazy_cached("research")
|
|
293
|
-
output = research_mod.aggregate_social_sentiment(
|
|
294
|
-
query=query, platforms=platforms, platform_results=platform_results,
|
|
295
|
-
)
|
|
296
|
-
else:
|
|
297
|
-
all_results: list = []
|
|
298
|
-
for p in platforms:
|
|
299
|
-
all_results.extend(platform_results.get(p) or [])
|
|
300
|
-
output = {
|
|
301
|
-
"query": query,
|
|
302
|
-
"platforms": platforms,
|
|
303
|
-
"results": all_results,
|
|
304
|
-
"count": len(all_results),
|
|
305
|
-
"engines_used": engines_used,
|
|
306
|
-
}
|
|
307
|
-
if errors:
|
|
308
|
-
output["errors"] = errors
|
|
309
|
-
return _ok(output, pretty=pretty)
|
|
310
|
-
|
|
311
374
|
elif name == "argo_evidence":
|
|
312
375
|
results_json_str = arguments.get("results_json", "")
|
|
313
376
|
if not results_json_str or not results_json_str.strip():
|
|
@@ -347,13 +410,45 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
|
347
410
|
return _ok(result, pretty=pretty)
|
|
348
411
|
|
|
349
412
|
elif name == "argo_fetch":
|
|
350
|
-
|
|
413
|
+
url = arguments["url"]
|
|
414
|
+
mode = arguments.get("mode", "text")
|
|
415
|
+
|
|
416
|
+
# 微信公众号文章原生自适应
|
|
417
|
+
if "mp.weixin.qq.com" in url or mode == "article":
|
|
418
|
+
article_mod = _lazy_cached("article")
|
|
419
|
+
try:
|
|
420
|
+
out = article_mod.fetch_article(
|
|
421
|
+
url,
|
|
422
|
+
timeout=_env_int("ARGO_MCP_TIMEOUT_FETCH",
|
|
423
|
+
_int_param(arguments, "timeout", 30)),
|
|
424
|
+
)
|
|
425
|
+
except ValueError as e:
|
|
426
|
+
return {"content": [{"type": "text", "text": _dumps({"error": str(e)})}],
|
|
427
|
+
"isError": True}
|
|
428
|
+
if out.get("ok"):
|
|
429
|
+
max_c = _int_param(arguments, "max_chars", 20000)
|
|
430
|
+
if len(out.get("content", "")) > max_c:
|
|
431
|
+
out["content"] = out["content"][:max_c]
|
|
432
|
+
out["truncated"] = True
|
|
433
|
+
return _ok(out, pretty=pretty)
|
|
434
|
+
|
|
435
|
+
# PDF 文档原生自适应
|
|
436
|
+
if url.lower().endswith(".pdf") or ".pdf?" in url.lower() or mode == "pdf":
|
|
437
|
+
pdf_mod = _lazy_cached("pdf_extract")
|
|
438
|
+
result = pdf_mod.extract_pdf(
|
|
439
|
+
url_or_path=url,
|
|
440
|
+
pages=arguments.get("pages"),
|
|
441
|
+
password=arguments.get("password"),
|
|
442
|
+
)
|
|
443
|
+
return _ok(result, pretty=pretty)
|
|
444
|
+
|
|
445
|
+
if mode == "extract":
|
|
351
446
|
extract_mod = _lazy_cached("extract")
|
|
352
447
|
fetch_mod = _lazy_cached("fetch_v3")
|
|
353
448
|
emode = arguments.get("extract_mode", "all")
|
|
354
449
|
max_chars = _clamp_int(_int_param(arguments, "max_chars", 8000), 8000, 500, 50000)
|
|
355
450
|
fetch_result = fetch_mod.fetch_page_v3(
|
|
356
|
-
|
|
451
|
+
url, max_chars=max_chars,
|
|
357
452
|
timeout=_env_int("ARGO_MCP_TIMEOUT_FETCH",
|
|
358
453
|
_int_param(arguments, "timeout", 15)), raw=True)
|
|
359
454
|
if not fetch_result["success"]:
|
|
@@ -375,7 +470,7 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
|
375
470
|
focus_query = arguments.get("focus")
|
|
376
471
|
fetch_v3_mod = _lazy_cached("fetch_v3")
|
|
377
472
|
result = fetch_v3_mod.fetch_v3(
|
|
378
|
-
url=
|
|
473
|
+
url=url,
|
|
379
474
|
max_chars=fetch_v3_mod._focus_fetch_chars(
|
|
380
475
|
_int_param(arguments, "max_chars", 8000), focus_query),
|
|
381
476
|
timeout=_env_int("ARGO_MCP_TIMEOUT_FETCH", _int_param(arguments, "timeout", 15)),
|
|
@@ -422,49 +517,6 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
|
422
517
|
"isError": True,
|
|
423
518
|
}
|
|
424
519
|
|
|
425
|
-
elif name == "argo_pdf":
|
|
426
|
-
pdf_mod = _lazy_cached("pdf_extract")
|
|
427
|
-
result = pdf_mod.extract_pdf(
|
|
428
|
-
url_or_path=arguments["url"],
|
|
429
|
-
pages=arguments.get("pages"),
|
|
430
|
-
password=arguments.get("password"),
|
|
431
|
-
)
|
|
432
|
-
return _ok(result, pretty=pretty)
|
|
433
|
-
|
|
434
|
-
elif name == "argo_article":
|
|
435
|
-
article_mod = _lazy_cached("article")
|
|
436
|
-
try:
|
|
437
|
-
out = article_mod.fetch_article(
|
|
438
|
-
arguments["url"],
|
|
439
|
-
timeout=_env_int("ARGO_MCP_TIMEOUT_FETCH",
|
|
440
|
-
_int_param(arguments, "timeout", 30)),
|
|
441
|
-
)
|
|
442
|
-
except ValueError as e:
|
|
443
|
-
return {"content": [{"type": "text", "text": _dumps({"error": str(e)})}],
|
|
444
|
-
"isError": True}
|
|
445
|
-
if out.get("ok"):
|
|
446
|
-
max_c = _int_param(arguments, "max_chars", 20000)
|
|
447
|
-
if len(out.get("content", "")) > max_c:
|
|
448
|
-
out["content"] = out["content"][:max_c]
|
|
449
|
-
out["truncated"] = True
|
|
450
|
-
return _ok(out, pretty=pretty)
|
|
451
|
-
|
|
452
|
-
elif name == "argo_job":
|
|
453
|
-
job_mod = _lazy_cached("job")
|
|
454
|
-
try:
|
|
455
|
-
out = job_mod.search(
|
|
456
|
-
arguments["query"],
|
|
457
|
-
city=arguments.get("city", ""),
|
|
458
|
-
num=_clamp_int(arguments.get("num", 5), 5, 1, 20),
|
|
459
|
-
platforms=arguments.get("platforms", ""),
|
|
460
|
-
loose=bool(arguments.get("loose", False)),
|
|
461
|
-
fetch_n=_clamp_int(arguments.get("fetch_detail", 0), 0, 0, 10),
|
|
462
|
-
)
|
|
463
|
-
except ValueError as e:
|
|
464
|
-
return {"content": [{"type": "text", "text": _dumps({"error": str(e)})}],
|
|
465
|
-
"isError": True}
|
|
466
|
-
return _ok(out, pretty=pretty)
|
|
467
|
-
|
|
468
520
|
surface = _lazy_cached("mcp_handlers_surface")
|
|
469
521
|
surface_result = surface.handle_surface_tool(name, arguments, pretty=pretty)
|
|
470
522
|
if surface_result is not None:
|
package/scripts/mcp_server.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
mcp_server.py — Argo MCP 服务入口(P2-4 拆分后为聚合薄壳)
|
|
4
4
|
|
|
5
5
|
原 970 行单文件已拆为三模块,本文件只做聚合与兼容导出:
|
|
6
|
-
mcp_tools.py 工具 schema 唯一来源(
|
|
6
|
+
mcp_tools.py 工具 schema 唯一来源(19 个工具;tools/list 默认 CORE 4 个)
|
|
7
7
|
mcp_handlers.py 路径引导 + 延迟导入 + 结果压缩 + execute_tool + 预热
|
|
8
8
|
mcp_transport.py JSON-RPC 分发(handle_rpc)+ stdio 帧协议(run_stdio)
|
|
9
9
|
|