argo-search 2.16.0 → 2.17.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 +3 -1
- package/README.es.md +9 -4
- package/README.ja.md +9 -4
- package/README.ko.md +9 -4
- package/README.md +9 -4
- package/README.zh.md +9 -4
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +115 -18
- package/backends/engine_registry.yaml +11 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +10 -0
- package/docs/CHANGELOG.md +17 -1
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +32 -30
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/crossref.yaml +2 -0
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/openalex.yaml +9 -2
- package/package.json +2 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +57 -63
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +109 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +49 -6
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +234 -497
- package/packages/dsh-plugin/package.json +4 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
- package/packages/dsh-plugin/test/workbench.test.js +337 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/config_cache.py +4 -3
- package/scripts/daemon.py +9 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +27 -47
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +50 -0
- package/scripts/engines_base.py +7 -16
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_tech.py +16 -16
- package/scripts/engines_fields.py +23 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/numeric_verify.py +9 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route_combo.py +13 -1
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/sub-skills/ego-search/README.md +9 -0
- package/sub-skills/ego-search/scripts/ego_search.py +182 -15
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
package/scripts/pre-commit
CHANGED
|
@@ -50,9 +50,13 @@
|
|
|
50
50
|
# AGENTS.md 的「~13s」漂移注释修为实测值:hook 实测 20.8s(已超自设 20s
|
|
51
51
|
# 红线)回到 ~17s,新门禁是在这个余量里加的。
|
|
52
52
|
# 2026-11-14 清单单真源收口:42 文件手工枚举迁到 tests/gate_manifest.txt
|
|
53
|
-
# (49 条:42 + env/config 对账门补册 6 + 本门禁自身 1
|
|
54
|
-
#
|
|
55
|
-
#
|
|
53
|
+
# (49 条:42 + env/config 对账门补册 6 + 本门禁自身 1),漏册由
|
|
54
|
+
# test_gate_manifest.py 反向断言拦截,本文件不再随新门禁逐轮追加。
|
|
55
|
+
# 2026-11-21 根因修复:13 项 skip 豁免全部入册(实测均 <1s),清单 73 条;
|
|
56
|
+
# 串行实测 19.2~21.5s 已跨 20s 红线,故改 4 片并行(墙钟 ~8s,824 用例
|
|
57
|
+
# 零丢失)。取消 skip 层的原因:豁免项只由 CI 兜底,而本地连续 36 笔未推、
|
|
58
|
+
# CI 零覆盖,两次「本地绿、全量红」由此漏库(test_http_attribution、
|
|
59
|
+
# test_subprocess_encoding_gate)。拦截点必须留在本地。
|
|
56
60
|
#
|
|
57
61
|
# 安装:bash scripts/install.sh 自动装调度器 hooks/pre-commit(原有 hook 改名
|
|
58
62
|
# pre-commit.user 先跑,再直接执行本文件,不拷贝)。手动跑:sh scripts/pre-commit
|
|
@@ -113,7 +117,7 @@ if [ -z "$PY" ]; then
|
|
|
113
117
|
exit 1
|
|
114
118
|
fi
|
|
115
119
|
|
|
116
|
-
printf "[pre-commit] argo
|
|
120
|
+
printf "[pre-commit] argo 快门禁(74 条 4 片并行,实测 ~8s,解释器 %s;全量回归请手动跑 tests/)...\n" "$PY"
|
|
117
121
|
# 测试清单单真源:tests/gate_manifest.txt(2026-11-14 收口)。
|
|
118
122
|
# 清单曾在此手工枚举 42 个文件,每轮新门禁「漏一道加一道」(头注释史
|
|
119
123
|
# 至少 6 轮),env/config 对账门三道长期漏册——现由 tests/test_gate_manifest.py
|
|
@@ -126,7 +130,44 @@ if [ ! -f "$MANIFEST" ]; then
|
|
|
126
130
|
echo "[pre-commit] 缺 $MANIFEST,快门禁清单无真源,门禁视为失败" >&2
|
|
127
131
|
exit 1
|
|
128
132
|
fi
|
|
129
|
-
|
|
133
|
+
# 新增测试文件当场归类(2026-11-21 审计):test_gate_manifest.py 的词根
|
|
134
|
+
# 反向断言拦不住命名不带 gate/… 的 <1s 文件(两个漏册实证),本检查把
|
|
135
|
+
# 拦截点前移到 commit 时刻——staged 新增 tests/test_*.py 必须入册;存量
|
|
136
|
+
# 未登记文件不受影响。实测 <0.2s。
|
|
137
|
+
"$PY" scripts/gate_manifest_check.py
|
|
138
|
+
|
|
139
|
+
# 快门禁分片并行(2026-11-21 根因修复)。
|
|
140
|
+
#
|
|
141
|
+
# 为什么必须并行:清单是全量收录(skip 豁免层已取消),串行实测 19.2~21.5s,
|
|
142
|
+
# 波动跨过自设 20s 红线——而「慢于 20s 就会被 --no-verify 绕过」正是这份
|
|
143
|
+
# 清单当初把 13 道门豁免给 CI 的原因。豁免的代价已实证两次:本地连续 36 笔
|
|
144
|
+
# 未推、CI 零覆盖,test_http_attribution 与 test_subprocess_encoding_gate
|
|
145
|
+
# 两次「本地绿、全量红」漏进库。所以正解不是把门挪走,而是让本地跑得起:
|
|
146
|
+
# 4 片并行墙钟 ~8s(实测两轮 7.88/7.77s,824 用例零丢失、4 片全 rc=0)。
|
|
147
|
+
#
|
|
148
|
+
# 分片插件与 CI 同源(pytest-split + tests/.test_durations),保证本地与
|
|
149
|
+
# CI 看到同一份清单。pytest-split 缺失时回落串行并显式告警——不静默跳过。
|
|
150
|
+
GATE_SPLITS=4
|
|
151
|
+
if ! "$PY" -c "import pytest_split" >/dev/null 2>&1; then
|
|
152
|
+
echo "[pre-commit] 警告:缺 pytest-split,快门禁回落串行(本地与 CI 清单仍一致,只是慢)" >&2
|
|
153
|
+
"$PY" -m pytest -q -p no:cacheprovider $(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST")
|
|
154
|
+
else
|
|
155
|
+
pids=""; failed=0
|
|
156
|
+
for g in $(seq 1 "$GATE_SPLITS"); do
|
|
157
|
+
"$PY" -m pytest -q -p no:cacheprovider \
|
|
158
|
+
--splits "$GATE_SPLITS" --group "$g" \
|
|
159
|
+
--durations-path tests/.test_durations \
|
|
160
|
+
$(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST") &
|
|
161
|
+
pids="$pids $!"
|
|
162
|
+
done
|
|
163
|
+
for p in $pids; do
|
|
164
|
+
wait "$p" || failed=1
|
|
165
|
+
done
|
|
166
|
+
if [ "$failed" -ne 0 ]; then
|
|
167
|
+
echo "[pre-commit] 快门禁有分片失败(见上方输出)" >&2
|
|
168
|
+
exit 1
|
|
169
|
+
fi
|
|
170
|
+
fi
|
|
130
171
|
|
|
131
172
|
# 派生件一致性门禁(P0-2):写完 spec 不跑 sync 就提交,派生件会过期。
|
|
132
173
|
# 实测 0.13s,进 pre-commit 不触发 --no-verify 绕过。
|
|
@@ -135,15 +176,23 @@ if ! "$PY" scripts/sync_backends.py --check; then
|
|
|
135
176
|
echo "[pre-commit] 派生件过期,正在自动执行同步刷新..."
|
|
136
177
|
"$PY" scripts/sync_backends.py
|
|
137
178
|
"$PY" scripts/gen_engine_catalog.py
|
|
138
|
-
echo "[pre-commit] 派生件已自动刷新,请检查并暂存相关修改: git add backends/ docs/ENGINE_CATALOG.md
|
|
179
|
+
echo "[pre-commit] 派生件已自动刷新,请检查并暂存相关修改: git add backends/ docs/ENGINE_CATALOG.md" >&2
|
|
139
180
|
# 这里必须 exit 1,不能刷新后放行:钩子改的是工作区,暂存区里仍是旧版
|
|
140
181
|
# 派生件;若返回 0,git 会把旧内容提交进去,校验反而形同虚设。也不自动
|
|
141
182
|
# git add——把「刷新了什么」留给用户过目。
|
|
142
183
|
exit 1
|
|
143
184
|
fi
|
|
144
185
|
|
|
145
|
-
|
|
146
|
-
|
|
186
|
+
# 子技能快门禁(2026-11-21 方案 B 补盲):ego-search 回归测试耗时 <1s,
|
|
187
|
+
# 纳入本地快门禁消除子技能门禁真空带。
|
|
188
|
+
if [ -d sub-skills/ego-search/tests ]; then
|
|
189
|
+
"$PY" -m pytest -q -p no:cacheprovider sub-skills/ego-search/tests
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
# DSH 插件全量 Node 测试(2026-11-21 方案 B 补盲):含 workbench / concurrency /
|
|
193
|
+
# client / index / diagnostics / config / size-gate,136 用例实测 ~2.5s。
|
|
194
|
+
if command -v node >/dev/null 2>&1 && [ -d packages/dsh-plugin/test ]; then
|
|
195
|
+
node --test packages/dsh-plugin/test/*.test.js
|
|
147
196
|
fi
|
|
148
197
|
|
|
149
198
|
# 高风险提交的检查清单提示(2026-11-10):只警告不硬拦。
|
|
@@ -53,11 +53,99 @@ _SITE_RE = re.compile(r"(?<![\w-])(-?)site:([a-zA-Z0-9.\-]+)(?:\s+OR(?=\s+site:)
|
|
|
53
53
|
_LANG_RE = re.compile(r"(?<![\w-])lang:([a-zA-Z,]+)")
|
|
54
54
|
# after:/before: 的值:年份或 YYYY-MM-DD
|
|
55
55
|
_DATE_RE = re.compile(r"(?<![\w-])(after|before):(\d{4}(?:-\d{2}-\d{2})?)")
|
|
56
|
+
# country:/region: 的值:ISO-2 代码或单/双词英文国名(如 country:de / region:united states)
|
|
57
|
+
_COUNTRY_RE = re.compile(r"(?<![\w-])(?:country|region)[:=]([A-Za-z][A-Za-z\- ]{0,32})")
|
|
56
58
|
# 排除短语:-"..."(先于单词排除处理)
|
|
57
59
|
_EXCL_PHRASE_RE = re.compile(r'-\s*"([^"]+)"')
|
|
58
60
|
# 排除单词:-词(字母数字或 CJK 串;连字符后紧跟非空白非连字符)
|
|
59
61
|
_EXCL_TERM_RE = re.compile(r"(?<![\w\"])-(\S+)")
|
|
60
62
|
|
|
63
|
+
# 常用 ISO 3166-1 alpha-2 代码与名称映射(零外部依赖,覆盖主流区域检索)
|
|
64
|
+
_COUNTRY_ALIASES: dict[str, str] = {
|
|
65
|
+
"us": "US", "usa": "US", "united states": "US", "america": "US",
|
|
66
|
+
"cn": "CN", "china": "CN",
|
|
67
|
+
"gb": "GB", "uk": "GB", "united kingdom": "GB", "britain": "GB",
|
|
68
|
+
"de": "DE", "germany": "DE",
|
|
69
|
+
"fr": "FR", "france": "FR",
|
|
70
|
+
"jp": "JP", "japan": "JP",
|
|
71
|
+
"kr": "KR", "south korea": "KR", "korea": "KR",
|
|
72
|
+
"sg": "SG", "singapore": "SG",
|
|
73
|
+
"ca": "CA", "canada": "CA",
|
|
74
|
+
"au": "AU", "australia": "AU",
|
|
75
|
+
"in": "IN", "india": "IN",
|
|
76
|
+
"hk": "HK", "hong kong": "HK",
|
|
77
|
+
"tw": "TW", "taiwan": "TW",
|
|
78
|
+
"nl": "NL", "netherlands": "NL",
|
|
79
|
+
"ch": "CH", "switzerland": "CH",
|
|
80
|
+
"se": "SE", "sweden": "SE",
|
|
81
|
+
"es": "ES", "spain": "ES",
|
|
82
|
+
"it": "IT", "italy": "IT",
|
|
83
|
+
"br": "BR", "brazil": "BR",
|
|
84
|
+
"ru": "RU", "russia": "RU",
|
|
85
|
+
}
|
|
86
|
+
_TAVILY_COUNTRY_NAME: dict[str, str] = {
|
|
87
|
+
"US": "united states", "CN": "china", "GB": "united kingdom",
|
|
88
|
+
"DE": "germany", "FR": "france", "JP": "japan", "KR": "south korea",
|
|
89
|
+
"SG": "singapore", "CA": "canada", "AU": "australia", "IN": "india",
|
|
90
|
+
"HK": "hong kong", "TW": "taiwan", "NL": "netherlands",
|
|
91
|
+
"CH": "switzerland", "SE": "sweden", "ES": "spain", "IT": "italy",
|
|
92
|
+
"BR": "brazil", "RU": "russia",
|
|
93
|
+
}
|
|
94
|
+
_CODE_TOPIC_RE = re.compile(
|
|
95
|
+
r"\b(github|gitlab|npm|pnpm|cargo|pip|pypi|stackoverflow|python|rust|"
|
|
96
|
+
r"typescript|javascript|golang|react|vue|docker|kubernetes|k8s|linux|"
|
|
97
|
+
r"api|sdk|graphql|grpc|bug|error|traceback|compiler)\b"
|
|
98
|
+
r"|(?:代码|函数|接口|报错|崩溃|源码|组件|版本号|仓库|异常|编译)",
|
|
99
|
+
re.I,
|
|
100
|
+
)
|
|
101
|
+
_RESEARCH_TOPIC_RE = re.compile(
|
|
102
|
+
r"\b(arxiv|paper|research|benchmark|ablation|dataset|neurips|icml|iclr|cvpr|acl|ieee)\b"
|
|
103
|
+
r"|(?:论文|学术|评测|基准|消融实验|数据集|研报|文献)",
|
|
104
|
+
re.I,
|
|
105
|
+
)
|
|
106
|
+
_FINANCE_TOPIC_RE = re.compile(
|
|
107
|
+
r"\b(stock|shares|nasdaq|nyse|sec|10-k|10-q|earnings|revenue|market cap|valuation|ipo|dividend|ebitda)\b"
|
|
108
|
+
r"|(?:财报|股价|营收|市值|估值|财季|分红|股票|证券|上市|净利润)",
|
|
109
|
+
re.I,
|
|
110
|
+
)
|
|
111
|
+
_NEWS_TOPIC_RE = re.compile(
|
|
112
|
+
r"\b(news|breaking|announced|announcement|press release|headline|coverage)\b"
|
|
113
|
+
r"|(?:新闻|快讯|发布会|报道|最新消息|突发|头条)",
|
|
114
|
+
re.I,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def resolve_country_code(raw: str) -> str | None:
|
|
119
|
+
"""将 ISO-2 代码或常见英文国名归一化为大写 alpha-2,无法识别返回 None。"""
|
|
120
|
+
key = re.sub(r"\s+", " ", (raw or "").strip().lower())
|
|
121
|
+
return _COUNTRY_ALIASES.get(key)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _strip_country_directive(text: str, ops: dict[str, Any]) -> str:
|
|
125
|
+
"""抽取首个 country:/region: 指令(最长合法前缀优先;无效值也剥离防污染)。"""
|
|
126
|
+
m = _COUNTRY_RE.search(text)
|
|
127
|
+
if not m:
|
|
128
|
+
return text
|
|
129
|
+
tokens = m.group(1).strip().split()[:3]
|
|
130
|
+
matched_val = ""
|
|
131
|
+
resolved: str | None = None
|
|
132
|
+
for n in range(len(tokens), 0, -1):
|
|
133
|
+
cand = " ".join(tokens[:n])
|
|
134
|
+
code = resolve_country_code(cand)
|
|
135
|
+
if code:
|
|
136
|
+
matched_val = cand
|
|
137
|
+
resolved = code
|
|
138
|
+
break
|
|
139
|
+
if not matched_val:
|
|
140
|
+
matched_val = tokens[0] if tokens else ""
|
|
141
|
+
prefix_end = m.start(1)
|
|
142
|
+
cut_end = prefix_end + len(matched_val)
|
|
143
|
+
raw_directive = text[m.start():cut_end].strip()
|
|
144
|
+
ops["dropped"].append(raw_directive)
|
|
145
|
+
if resolved:
|
|
146
|
+
ops["country"] = resolved
|
|
147
|
+
return text[:m.start()] + " " + text[cut_end:]
|
|
148
|
+
|
|
61
149
|
|
|
62
150
|
def parse_query_operators(query: str) -> tuple[str, dict[str, Any]]:
|
|
63
151
|
"""抽取查询操作符 → (clean_query, operators)。
|
|
@@ -99,6 +187,9 @@ def parse_query_operators(query: str) -> tuple[str, dict[str, Any]]:
|
|
|
99
187
|
return _take(m)
|
|
100
188
|
text = _DATE_RE.sub(_date_sub, text)
|
|
101
189
|
|
|
190
|
+
# 3.5) 国家/区域指令(country:de / region:united states)
|
|
191
|
+
text = _strip_country_directive(text, ops)
|
|
192
|
+
|
|
102
193
|
# 4) 排除短语(先于 -词,避免 " 被当词的一部分)
|
|
103
194
|
def _excl_phrase_sub(m: re.Match) -> str:
|
|
104
195
|
ops["exclude_terms"].append(m.group(1).strip())
|
|
@@ -143,6 +234,9 @@ def operator_cache_suffix(operators: dict[str, Any] | None) -> str:
|
|
|
143
234
|
if isinstance(v, (str, int, float)) and str(v).strip()]
|
|
144
235
|
if vals:
|
|
145
236
|
parts.append(f"{tag}={','.join(vals)}")
|
|
237
|
+
cc = str(ops.get("country") or "").strip().upper()
|
|
238
|
+
if cc:
|
|
239
|
+
parts.append(f"cc={cc}")
|
|
146
240
|
return "".join(f"|{p}" for p in parts)
|
|
147
241
|
|
|
148
242
|
|
|
@@ -192,5 +286,139 @@ def filter_results_by_sites(
|
|
|
192
286
|
def _empty_ops() -> dict[str, Any]:
|
|
193
287
|
return {
|
|
194
288
|
"sites": [], "exclude_sites": [], "exclude_terms": [],
|
|
195
|
-
"langs": [], "after": None, "before": None, "dropped": [],
|
|
289
|
+
"langs": [], "country": None, "after": None, "before": None, "dropped": [],
|
|
196
290
|
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def classify_hint_topic(query: str, sites: list[str] | None = None) -> str:
|
|
294
|
+
"""零 LLM 轻量主题判定:code / research / finance / news / general。"""
|
|
295
|
+
site_set = [str(s).lower() for s in (sites or [])]
|
|
296
|
+
if any(any(d in s for d in ("github.com", "gitlab.com", "stackoverflow.com")) for s in site_set):
|
|
297
|
+
return "code"
|
|
298
|
+
if _CODE_TOPIC_RE.search(query or ""):
|
|
299
|
+
return "code"
|
|
300
|
+
if any("arxiv.org" in s for s in site_set) or _RESEARCH_TOPIC_RE.search(query or ""):
|
|
301
|
+
return "research"
|
|
302
|
+
if _FINANCE_TOPIC_RE.search(query or ""):
|
|
303
|
+
return "finance"
|
|
304
|
+
if _NEWS_TOPIC_RE.search(query or ""):
|
|
305
|
+
return "news"
|
|
306
|
+
return "general"
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def is_evergreen_tech_query(query: str, sites: list[str] | None = None) -> bool:
|
|
310
|
+
"""常青技术/学术查询保护:非新闻场景不因 latest/recent 等词被误加短时效截断。"""
|
|
311
|
+
topic = classify_hint_topic(query, sites)
|
|
312
|
+
return topic in ("code", "research")
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _norm_ymd(raw: Any) -> str | None:
|
|
316
|
+
s = str(raw or "").strip()
|
|
317
|
+
if re.fullmatch(r"\d{4}-\d{2}-\d{2}", s):
|
|
318
|
+
return s
|
|
319
|
+
if re.fullmatch(r"\d{4}", s):
|
|
320
|
+
return f"{s}-01-01"
|
|
321
|
+
return None
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def compile_provider_params(
|
|
325
|
+
engine: str,
|
|
326
|
+
query: str,
|
|
327
|
+
*,
|
|
328
|
+
operators: dict[str, Any] | None = None,
|
|
329
|
+
since: str | None = None,
|
|
330
|
+
until: str | None = None,
|
|
331
|
+
depth: str = "fast",
|
|
332
|
+
) -> dict[str, Any]:
|
|
333
|
+
"""将统一操作符与意图提示编译为目标引擎的原生请求参数(零 LLM、纯函数)。"""
|
|
334
|
+
ops = operators if isinstance(operators, dict) else {}
|
|
335
|
+
sites = [str(s).strip().lower() for s in (ops.get("sites") or []) if str(s).strip()]
|
|
336
|
+
excl_sites = [str(s).strip().lower() for s in (ops.get("exclude_sites") or []) if str(s).strip()]
|
|
337
|
+
langs = [str(x).strip().lower() for x in (ops.get("langs") or []) if str(x).strip()]
|
|
338
|
+
country = str(ops.get("country") or "").strip().upper() or None
|
|
339
|
+
after = _norm_ymd(since or ops.get("after"))
|
|
340
|
+
before = _norm_ymd(until or ops.get("before"))
|
|
341
|
+
topic = classify_hint_topic(query, sites)
|
|
342
|
+
eng = (engine or "").strip().lower()
|
|
343
|
+
out: dict[str, Any] = {}
|
|
344
|
+
|
|
345
|
+
if eng == "exa":
|
|
346
|
+
cat_map = {"research": "publication", "news": "news", "finance": "financial report"}
|
|
347
|
+
if topic in cat_map:
|
|
348
|
+
out["category"] = cat_map[topic]
|
|
349
|
+
if sites:
|
|
350
|
+
out["includeDomains"] = sites
|
|
351
|
+
if excl_sites:
|
|
352
|
+
out["excludeDomains"] = excl_sites
|
|
353
|
+
if after:
|
|
354
|
+
out["startPublishedDate"] = f"{after}T00:00:00.000Z"
|
|
355
|
+
if before:
|
|
356
|
+
out["endPublishedDate"] = f"{before}T23:59:59.999Z"
|
|
357
|
+
if country:
|
|
358
|
+
out["userLocation"] = country
|
|
359
|
+
return out
|
|
360
|
+
|
|
361
|
+
if eng == "tavily":
|
|
362
|
+
if topic in ("news", "finance"):
|
|
363
|
+
out["topic"] = topic
|
|
364
|
+
if sites:
|
|
365
|
+
out["include_domains"] = sites
|
|
366
|
+
if excl_sites:
|
|
367
|
+
out["exclude_domains"] = excl_sites
|
|
368
|
+
if after:
|
|
369
|
+
out["start_date"] = after
|
|
370
|
+
if before:
|
|
371
|
+
out["end_date"] = before
|
|
372
|
+
if country and country in _TAVILY_COUNTRY_NAME:
|
|
373
|
+
out["country"] = _TAVILY_COUNTRY_NAME[country]
|
|
374
|
+
if langs:
|
|
375
|
+
# 官方 /search 有原生 language 参数(ISO 639-1 或英文名,boost 语义);
|
|
376
|
+
# 旧版剥离 lang 却不下发,语言约束静默丢失(2026-11-21 审计)。
|
|
377
|
+
# exa 经官方文档逐参数核对无语言参数,维持剥给路由不改(勿编造契约)。
|
|
378
|
+
out["language"] = langs[0]
|
|
379
|
+
return out
|
|
380
|
+
|
|
381
|
+
if eng == "parallel":
|
|
382
|
+
policy: dict[str, Any] = {}
|
|
383
|
+
if sites:
|
|
384
|
+
policy["include_domains"] = sites
|
|
385
|
+
if excl_sites:
|
|
386
|
+
policy["exclude_domains"] = excl_sites
|
|
387
|
+
if after:
|
|
388
|
+
policy["after_date"] = after
|
|
389
|
+
if before:
|
|
390
|
+
policy["before_date"] = before
|
|
391
|
+
if policy:
|
|
392
|
+
out["source_policy"] = policy
|
|
393
|
+
return out
|
|
394
|
+
|
|
395
|
+
if eng == "you":
|
|
396
|
+
if sites:
|
|
397
|
+
out["boost_domains"] = sites
|
|
398
|
+
if country:
|
|
399
|
+
out["country"] = country
|
|
400
|
+
if langs:
|
|
401
|
+
out["language"] = langs[0]
|
|
402
|
+
return out
|
|
403
|
+
|
|
404
|
+
return out
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def format_exa_notices(notices: Any) -> str | None:
|
|
408
|
+
"""将 Exa 3.0 响应中的 notices 扁平化为单行模型可读提示(去重、容错)。"""
|
|
409
|
+
if not isinstance(notices, list) or not notices:
|
|
410
|
+
return None
|
|
411
|
+
lines: list[str] = []
|
|
412
|
+
for n in notices:
|
|
413
|
+
line = ""
|
|
414
|
+
if isinstance(n, str):
|
|
415
|
+
line = n.strip()
|
|
416
|
+
elif isinstance(n, dict):
|
|
417
|
+
for key in ("message", "description", "text", "notice"):
|
|
418
|
+
val = n.get(key)
|
|
419
|
+
if isinstance(val, str) and val.strip():
|
|
420
|
+
line = val.strip()
|
|
421
|
+
break
|
|
422
|
+
if line and line not in lines:
|
|
423
|
+
lines.append(line)
|
|
424
|
+
return f"Exa: {' | '.join(lines)}" if lines else None
|
package/scripts/quota.py
CHANGED
|
@@ -223,8 +223,6 @@ class QuotaManager:
|
|
|
223
223
|
self._lock = threading.RLock()
|
|
224
224
|
self._profiles: dict = {}
|
|
225
225
|
self._state: dict = {}
|
|
226
|
-
self._last_save_ts: float = 0.0 # 写盘节流时间戳
|
|
227
|
-
self._last_save_interval: float = 30.0 # 写盘节流间隔(秒)
|
|
228
226
|
self._load_profiles()
|
|
229
227
|
self._load_state()
|
|
230
228
|
# 热读监视器(跨进程):其他进程(CLI/另一客户端 server)改写
|
|
@@ -325,41 +323,25 @@ class QuotaManager:
|
|
|
325
323
|
print(f"[quota] 状态文件损坏,保留旧状态: {_state_path()}",
|
|
326
324
|
file=sys.stderr)
|
|
327
325
|
|
|
328
|
-
def _save_state(self, force: bool = False) -> None:
|
|
329
|
-
"""原子写状态(临时文件名进程内唯一,见 argo_paths.atomic_write_json)。
|
|
330
|
-
|
|
331
|
-
⚠️ 生产写入一律走 _mutate_locked(文件锁内「重读→改→写」)。本方法
|
|
332
|
-
是**无锁读改写 + 30s 节流**:在锁序列里调用它,节流窗口内的变更会被
|
|
333
|
-
后写者整体覆盖——复刻 017b01a 在 circuit_breaker 修掉的跨进程丢更新。
|
|
334
|
-
当前仅测试引用(test_audit_fixes 直调、其余打桩跳写);接入任何生产
|
|
335
|
-
路径前必须先包 file_lock 并去掉节流语义。
|
|
336
|
-
|
|
337
|
-
旧实现用固定 `quota.json.tmp`:多进程(CLI 与 MCP server 并行、
|
|
338
|
-
或评测脚本)同时写时互相搬走/删除对方的 tmp,replace 抛
|
|
339
|
-
FileNotFoundError,且失败方本次计数直接丢失。
|
|
340
|
-
|
|
341
|
-
写盘节流(2026-09-27):identity memory 已有 30s 节流,quota 此前没有。
|
|
342
|
-
一次 5 引擎搜索触发 5 次 record_many,每次都是全量序列化 + rename。
|
|
343
|
-
加节流后,30s 内的多次写只落盘最后一次,磁盘 I/O 降 60-80%。
|
|
344
|
-
状态丢失窗口 30s(进程崩溃时),可接受:配额计数是观测层,不是安全边界。
|
|
345
|
-
"""
|
|
346
|
-
now = time.time()
|
|
347
|
-
if not force and (now - self._last_save_ts) < self._last_save_interval:
|
|
348
|
-
return
|
|
349
|
-
argo_paths.atomic_write_json(_state_path(), self._state)
|
|
350
|
-
self._last_save_ts = now
|
|
351
|
-
|
|
352
326
|
def _mutate_locked(self, mutator) -> None:
|
|
353
327
|
"""跨进程安全的「重读 → 改 → 写入文件」序列。
|
|
354
328
|
|
|
355
329
|
进程内 threading.Lock 只挡得住同进程线程;CLI / MCP server /
|
|
356
330
|
评测脚本三者并行时,各自读到旧状态、各自 +1、后写者覆盖前写者,
|
|
357
|
-
|
|
331
|
+
计数直接丢失。这里在进程内锁 + 文件锁内重读最新磁盘态,保证增量不丢,
|
|
332
|
+
写盘后刷新 `_state_hot` 基线避免本进程下一次访问误判磁盘变化再重读。
|
|
358
333
|
"""
|
|
359
|
-
with
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
334
|
+
with self._lock:
|
|
335
|
+
with argo_paths.file_lock(_state_path()):
|
|
336
|
+
self._load_state()
|
|
337
|
+
mutator()
|
|
338
|
+
argo_paths.atomic_write_json(_state_path(), self._state)
|
|
339
|
+
if self._state_hot is not None:
|
|
340
|
+
try:
|
|
341
|
+
self._state_hot.reset()
|
|
342
|
+
self._state_hot.changed()
|
|
343
|
+
except Exception:
|
|
344
|
+
pass
|
|
363
345
|
|
|
364
346
|
def record(self, engine: str, success: bool = True, credits: int = 1) -> None:
|
|
365
347
|
"""记录一次 API 调用(单条,跨进程安全)。"""
|
|
@@ -430,7 +412,7 @@ class QuotaManager:
|
|
|
430
412
|
"""周期重置的 load-modify-write,**调用方须已持文件锁**。
|
|
431
413
|
|
|
432
414
|
get_remaining_ratio / is_available 此前各抄了一份这段逻辑,也各抄了
|
|
433
|
-
一份「threading.Lock
|
|
415
|
+
一份「threading.Lock 下改完就地写盘」的写法——于是周期边界那一刻
|
|
434
416
|
的并发写会互相覆盖整个状态文件。统一走这里:先判是否过期,过期才在
|
|
435
417
|
锁内重读并归零。
|
|
436
418
|
"""
|
|
@@ -589,7 +571,7 @@ class QuotaManager:
|
|
|
589
571
|
def _refresh_remote_state_locked(self, engine: str, now: float) -> None:
|
|
590
572
|
"""周期边界或换 Key 自愈(调用方须已持锁)。
|
|
591
573
|
|
|
592
|
-
走 _mutate_locked
|
|
574
|
+
走 _mutate_locked 而非锁外就地写盘:这是 load-modify-write,
|
|
593
575
|
只用 threading.Lock 时 CLI 与 MCP 并发会互相覆盖整个状态文件。
|
|
594
576
|
"""
|
|
595
577
|
st = self._state.get(engine) or {}
|
|
@@ -657,7 +639,7 @@ class QuotaManager:
|
|
|
657
639
|
if limit is not None and (limit - st.get("used", 0)) <= 0:
|
|
658
640
|
return True
|
|
659
641
|
budget = (self._profiles.get(engine) or {}).get("budget_amount")
|
|
660
|
-
return budget is not None and
|
|
642
|
+
return budget is not None and _at_or_over_budget(st.get("cost_used", 0.0), budget)
|
|
661
643
|
|
|
662
644
|
def is_over_budget(self, engine: str) -> bool:
|
|
663
645
|
"""只判「月度预算是否用完」,不看次数/限频/远端配额。
|
|
@@ -774,11 +756,11 @@ class QuotaManager:
|
|
|
774
756
|
def get_stats(self) -> dict:
|
|
775
757
|
"""获取所有引擎的配额统计。"""
|
|
776
758
|
with self._lock:
|
|
759
|
+
self._fresh_locked()
|
|
777
760
|
stats = {}
|
|
778
|
-
for engine in self._profiles:
|
|
779
|
-
if engine.startswith("_") or not isinstance(
|
|
761
|
+
for engine, profile in list(self._profiles.items()):
|
|
762
|
+
if engine.startswith("_") or not isinstance(profile, dict):
|
|
780
763
|
continue
|
|
781
|
-
profile = self._profiles[engine]
|
|
782
764
|
# 残缺状态防御:state JSON 手工编辑/截断时 mark 可能非 dict,
|
|
783
765
|
# 与 _refresh_remote_state_locked 的 .get 计算方式保持一致
|
|
784
766
|
raw_mark = (self._state.get(engine) or {}).get("remote_exhausted")
|
package/scripts/release.py
CHANGED
|
@@ -220,14 +220,29 @@ def catalog_stale(root: Path) -> str:
|
|
|
220
220
|
return out
|
|
221
221
|
|
|
222
222
|
|
|
223
|
+
def readme_art_stale(root: Path) -> str:
|
|
224
|
+
script = root / "scripts" / "gen_readme_art.py"
|
|
225
|
+
if not script.is_file():
|
|
226
|
+
return ""
|
|
227
|
+
r = subprocess.run(
|
|
228
|
+
[sys.executable, str(script), "--check"],
|
|
229
|
+
cwd=root, capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
230
|
+
if r.returncode == 0:
|
|
231
|
+
return ""
|
|
232
|
+
return (r.stdout + r.stderr).strip() or "assets/readme/*.svg 过期,请跑 python3 scripts/gen_readme_art.py"
|
|
233
|
+
|
|
234
|
+
|
|
223
235
|
def check(root: Path = ROOT) -> list[str]:
|
|
224
|
-
"""全量校验:结构(release_check)+ 内容清单 +
|
|
236
|
+
"""全量校验:结构(release_check)+ 内容清单 + 目录计数 + 对外证据图。"""
|
|
225
237
|
ver = current_version(root)
|
|
226
238
|
problems = [f"release_check: {p}" for p in release_check.check(root)]
|
|
227
239
|
problems += content_problems(root, ver)
|
|
228
240
|
stale = catalog_stale(root)
|
|
229
241
|
if stale:
|
|
230
242
|
problems.append(f"目录计数: {stale}")
|
|
243
|
+
art_stale = readme_art_stale(root)
|
|
244
|
+
if art_stale:
|
|
245
|
+
problems.append(f"对外证据图: {art_stale}")
|
|
231
246
|
return problems
|
|
232
247
|
|
|
233
248
|
|
|
@@ -261,6 +261,16 @@ def evaluate_dossier_gates(dossier: dict[str, Any]) -> dict[str, Any]:
|
|
|
261
261
|
"detail": "有 source_grades 但零一手命中",
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
+
if dossier.get("stall_state") and isinstance(dossier["stall_state"], dict):
|
|
265
|
+
if dossier["stall_state"].get("stop_recommended"):
|
|
266
|
+
warnings.append({
|
|
267
|
+
"id": "coverage_stalled",
|
|
268
|
+
"detail": (
|
|
269
|
+
f"研究覆盖连续停滞({dossier['stall_state'].get('stop_reason') or 'coverage_stalled'}),"
|
|
270
|
+
"建议停止扩展检索并直接基于现有已验证证据收尾汇总"
|
|
271
|
+
),
|
|
272
|
+
})
|
|
273
|
+
|
|
264
274
|
if failures:
|
|
265
275
|
cap = engine_states.CONCLUSION_CAP_LOW
|
|
266
276
|
elif warnings:
|
|
@@ -268,9 +278,83 @@ def evaluate_dossier_gates(dossier: dict[str, Any]) -> dict[str, Any]:
|
|
|
268
278
|
else:
|
|
269
279
|
cap = engine_states.CONCLUSION_CAP_HIGH
|
|
270
280
|
|
|
271
|
-
|
|
281
|
+
out = {
|
|
272
282
|
"passed": not failures,
|
|
273
283
|
"conclusion_cap": cap,
|
|
274
284
|
"failures": failures,
|
|
275
285
|
"warnings": warnings,
|
|
276
286
|
}
|
|
287
|
+
stall = dossier.get("stall_state")
|
|
288
|
+
if isinstance(stall, dict) and stall.get("stop_recommended"):
|
|
289
|
+
out["stop_recommended"] = True
|
|
290
|
+
out["stop_reason"] = str(stall.get("stop_reason") or "coverage_stalled")
|
|
291
|
+
return out
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
class CoverageStallTracker:
|
|
295
|
+
"""研究覆盖高水位线停滞传感器。
|
|
296
|
+
|
|
297
|
+
铁律:仅新增 SERP 摘要或重复 URL 不算进展;只有新增 opened 正文阅读、
|
|
298
|
+
新覆盖工作包/实体属性格、或新锚定事实时才重置停滞计数。
|
|
299
|
+
连续 max_stalled_rounds 轮全零增长即返回 stop_recommended=True。
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
def __init__(self, max_stalled_rounds: int = 2) -> None:
|
|
303
|
+
self._max_stalled_rounds = max(0, int(max_stalled_rounds))
|
|
304
|
+
self._stalled_rounds = 0
|
|
305
|
+
self._stopped = False
|
|
306
|
+
self._seen_opened: set[str] = set()
|
|
307
|
+
self._seen_slots: set[str] = set()
|
|
308
|
+
self._seen_facts: set[str] = set()
|
|
309
|
+
# 多对多证据绑定:同一 opened URL 可支撑多个工作包任务(supports/contradicts/context)
|
|
310
|
+
self._task_bindings: list[dict[str, str]] = []
|
|
311
|
+
|
|
312
|
+
def bind_evidence(self, task_id: str, evidence_id: str, relation: str = "supports") -> None:
|
|
313
|
+
rel = relation if relation in ("supports", "contradicts", "context") else "context"
|
|
314
|
+
rec = {"task_id": str(task_id), "evidence_id": str(evidence_id), "relation": rel}
|
|
315
|
+
if rec not in self._task_bindings:
|
|
316
|
+
self._task_bindings.append(rec)
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def task_bindings(self) -> list[dict[str, str]]:
|
|
320
|
+
return list(self._task_bindings)
|
|
321
|
+
|
|
322
|
+
def observe_round(
|
|
323
|
+
self,
|
|
324
|
+
*,
|
|
325
|
+
opened_urls: list[str] | set[str] = (),
|
|
326
|
+
covered_slots: list[str] | set[str] = (),
|
|
327
|
+
grounded_facts: list[str] | set[str] = (),
|
|
328
|
+
) -> dict[str, Any]:
|
|
329
|
+
"""记录一轮完整检索波次的结果快照,返回停滞状态与增量统计。"""
|
|
330
|
+
opened = {str(u).strip() for u in opened_urls if str(u).strip()}
|
|
331
|
+
slots = {str(s).strip() for s in covered_slots if str(s).strip()}
|
|
332
|
+
facts = {str(f).strip() for f in grounded_facts if str(f).strip()}
|
|
333
|
+
|
|
334
|
+
new_opened = opened - self._seen_opened
|
|
335
|
+
new_slots = slots - self._seen_slots
|
|
336
|
+
new_facts = facts - self._seen_facts
|
|
337
|
+
|
|
338
|
+
self._seen_opened.update(opened)
|
|
339
|
+
self._seen_slots.update(slots)
|
|
340
|
+
self._seen_facts.update(facts)
|
|
341
|
+
|
|
342
|
+
if new_opened or new_slots or new_facts:
|
|
343
|
+
self._stalled_rounds = 0
|
|
344
|
+
elif self._max_stalled_rounds > 0:
|
|
345
|
+
self._stalled_rounds += 1
|
|
346
|
+
|
|
347
|
+
if self._max_stalled_rounds > 0 and self._stalled_rounds >= self._max_stalled_rounds:
|
|
348
|
+
self._stopped = True
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
"new_opened_count": len(new_opened),
|
|
352
|
+
"new_slots_count": len(new_slots),
|
|
353
|
+
"new_facts_count": len(new_facts),
|
|
354
|
+
"stalled_rounds": self._stalled_rounds,
|
|
355
|
+
"stop_recommended": self._stopped,
|
|
356
|
+
"stop_reason": f"coverage_stalled_x{self._stalled_rounds}" if self._stopped else "",
|
|
357
|
+
"total_opened": len(self._seen_opened),
|
|
358
|
+
"total_slots": len(self._seen_slots),
|
|
359
|
+
"total_facts": len(self._seen_facts),
|
|
360
|
+
}
|
package/scripts/route_combo.py
CHANGED
|
@@ -98,7 +98,8 @@ def _breaker_blocked(engine_id: str) -> bool:
|
|
|
98
98
|
"""
|
|
99
99
|
try:
|
|
100
100
|
from circuit_breaker import get_breaker
|
|
101
|
-
|
|
101
|
+
breaker = get_breaker()
|
|
102
|
+
st = breaker.status(engine_id)
|
|
102
103
|
except Exception as _exc:
|
|
103
104
|
import logging
|
|
104
105
|
logging.getLogger("unified_search").debug(
|
|
@@ -107,6 +108,17 @@ def _breaker_blocked(engine_id: str) -> bool:
|
|
|
107
108
|
import engine_states
|
|
108
109
|
state = st.get("state")
|
|
109
110
|
if state == engine_states.BREAKER_DISABLED:
|
|
111
|
+
# 打通熔断恢复环(2026-11-20 审计:3/5 disabled 引擎 2-12 天无探测字段,
|
|
112
|
+
# 路由硬跳过 → allow() 永不被调用 → 超冷却探测/env_fp/key_fp 自愈全部
|
|
113
|
+
# 死代码化)。这里只触发 allow() 的状态翻转(disabled→half_open 或指纹
|
|
114
|
+
# 自愈,锁内判冷却,零网络请求),本 combo 仍按 blocked 剔除(行为不变);
|
|
115
|
+
# 翻转后下次 status 读到 half_open 自然放行,真实调用走 allow() 正常探测。
|
|
116
|
+
try:
|
|
117
|
+
breaker.allow(engine_id)
|
|
118
|
+
except Exception as _exc: # 翻转失败不阻塞路由,但留痕(防再吞成静默)
|
|
119
|
+
import logging
|
|
120
|
+
logging.getLogger("unified_search").debug(
|
|
121
|
+
f"breaker.allow({engine_id!r}) 探测翻转失败,按 disabled 处理: {_exc!r}")
|
|
110
122
|
return True
|
|
111
123
|
return int(st.get("cooldown_remain") or 0) > 0
|
|
112
124
|
|