argo-search 2.15.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 +32 -5
- package/README.ja.md +32 -5
- package/README.ko.md +32 -5
- package/README.md +73 -19
- package/README.zh.md +73 -19
- package/SKILL.md +7 -7
- 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 +222 -24
- package/backends/engine_registry.yaml +26 -2
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +23 -3
- package/bin/argo +3 -0
- package/config.yaml +16 -0
- package/docs/CHANGELOG.md +31 -0
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +40 -37
- package/docs/MCP_SETUP.md +9 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +6 -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/docker_hub.yaml +1 -1
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/fxtwitter.yaml +1 -1
- 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/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -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/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/openalex.yaml +13 -4
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/sec_edgar.yaml +1 -1
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/vam.yaml +1 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/package.json +3 -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 +69 -74
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +115 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +50 -7
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
- package/packages/dsh-plugin/dsh/workbench.js +703 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +6 -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 +420 -0
- package/scripts/adaptive.py +13 -11
- package/scripts/argo_paths.py +2 -2
- package/scripts/badcase_ledger.py +9 -0
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +69 -70
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +91 -13
- package/scripts/config_cache.py +23 -10
- package/scripts/daemon.py +14 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +32 -49
- package/scripts/engine_env.py +13 -4
- 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 +31 -19
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch11.py +2 -1
- 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 +2 -2
- package/scripts/engines_builders_cn.py +7 -7
- 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 +34 -19
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +3 -2
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +19 -19
- package/scripts/engines_builders_weather.py +9 -4
- package/scripts/engines_fields.py +23 -0
- package/scripts/engines_http.py +50 -1
- package/scripts/engines_mcp.py +28 -6
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/evidence_loop.py +15 -1
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_v3.py +52 -93
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_transport.py +33 -9
- package/scripts/numeric_verify.py +12 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +46 -63
- package/scripts/recovery.py +19 -16
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route.py +8 -0
- package/scripts/route_combo.py +24 -3
- package/scripts/route_policy.py +1 -1
- package/scripts/search_attribution.py +20 -0
- package/scripts/search_entry.py +27 -0
- package/scripts/search_output.py +18 -7
- package/scripts/search_pipeline.py +3 -3
- package/scripts/semantic_evidence.py +20 -11
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +1 -0
- 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/zhihu_engine.py +2 -1
- package/scripts/source_audit.py +42 -7
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/usage_log.py +24 -9
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +7 -5
- package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
- package/sub-skills/ego-search/scripts/ego_search.py +195 -19
- 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/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/scripts/mcp_transport.py
CHANGED
|
@@ -39,7 +39,7 @@ except Exception: # pragma: no cover
|
|
|
39
39
|
|
|
40
40
|
# 版本来源:与 package.json / SKILL.md 保持一致(发布时统一升版;
|
|
41
41
|
# tests/test_consistency_gates.py 会四端对账,漂移即红)
|
|
42
|
-
ARGO_MCP_VERSION = "2.
|
|
42
|
+
ARGO_MCP_VERSION = "2.17.0"
|
|
43
43
|
|
|
44
44
|
_response_format = "content-length" # 根据客户端请求自动切换
|
|
45
45
|
|
|
@@ -62,9 +62,13 @@ def handle_rpc(method: str, params: dict[str, Any]) -> dict[str, Any]:
|
|
|
62
62
|
# 短指令:降 tools 上下文;细节在 tool schema。
|
|
63
63
|
# URL 在 results[].url(默认 envelope=False,不生成 sources)。
|
|
64
64
|
#
|
|
65
|
-
# 文案只写「CORE
|
|
66
|
-
#
|
|
67
|
-
#
|
|
65
|
+
# 文案只写「CORE 指哪几个」的语义;all 才打开的附加名单抄在这里,
|
|
66
|
+
# 是因为不少宿主不把 initialize instructions 之外的上下文透给模型,
|
|
67
|
+
# 不抄它们就永远不知道这些工具存在(2026-11-17 补全:此前抄了
|
|
68
|
+
# 11/15,漏 pdf/social_search/article/job 四个)。抄写漂移由机械
|
|
69
|
+
# 对拍锁死——test_mcp_consolidated_tools.py::
|
|
70
|
+
# test_instructions_matches_core 断言本名单 == TOOLS 全集 − CORE,
|
|
71
|
+
# 增删工具忘了改这里即红。
|
|
68
72
|
#
|
|
69
73
|
# 不点名 argo_local_search:它是真工具(domain=local 也能用),但
|
|
70
74
|
# 已不在默认注入面,写进「日常」文案会让模型去调一个没挂的工具。
|
|
@@ -75,7 +79,8 @@ def handle_rpc(method: str, params: dict[str, Any]) -> dict[str, Any]:
|
|
|
75
79
|
"argo_screenshot 截图)。argo_search 用 domain 切社交/招聘/本机。"
|
|
76
80
|
"其余工具默认不注入 schema,ARGO_MCP_TOOLS=all 打开:"
|
|
77
81
|
"local_search/local_read/recompute/evidence/clarify/crawl/"
|
|
78
|
-
"extract/preflight/answer/
|
|
82
|
+
"pdf/social_search/article/job/extract/preflight/answer/"
|
|
83
|
+
"watch/cite。"
|
|
79
84
|
),
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -150,10 +155,29 @@ def run_stdio():
|
|
|
150
155
|
continue
|
|
151
156
|
else:
|
|
152
157
|
_response_format = "content-length"
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
try:
|
|
159
|
+
length = int(header_str.split(":", 1)[1].strip())
|
|
160
|
+
except ValueError:
|
|
161
|
+
_send_error(None, -32700, "Invalid Content-Length")
|
|
162
|
+
continue
|
|
163
|
+
# 读取后续扩展头(如 Content-Type)直至空行,符合 LSP/MCP 帧规范
|
|
164
|
+
while True:
|
|
165
|
+
hdr_line = sys.stdin.buffer.readline()
|
|
166
|
+
if not hdr_line or hdr_line in (b"\r\n", b"\n"):
|
|
167
|
+
break
|
|
168
|
+
if length <= 0 or length > 10_000_000:
|
|
169
|
+
_send_error(None, -32600, "Invalid Request: Content-Length out of bounds")
|
|
170
|
+
continue
|
|
171
|
+
body = sys.stdin.buffer.read(length).decode("utf-8", errors="replace")
|
|
172
|
+
try:
|
|
173
|
+
request = json.loads(body)
|
|
174
|
+
except json.JSONDecodeError:
|
|
175
|
+
_send_error(None, -32700, "Parse error")
|
|
176
|
+
continue
|
|
177
|
+
|
|
178
|
+
if not isinstance(request, dict):
|
|
179
|
+
_send_error(None, -32600, "Invalid Request")
|
|
180
|
+
continue
|
|
157
181
|
|
|
158
182
|
method = request.get("method", "")
|
|
159
183
|
params = request.get("params", {})
|
|
@@ -209,7 +209,8 @@ def numeric_verify_results(results: list[dict[str, Any]],
|
|
|
209
209
|
return page, method
|
|
210
210
|
|
|
211
211
|
# 墙钟预算与 verify 同一开关(ARGO_VERIFY_BUDGET_S,默认 5s):到点未回的
|
|
212
|
-
# URL 记 pending,语义与 fetch
|
|
212
|
+
# URL 记 pending,语义与 fetch 失败一致。worker 上限 6 同理——核验是纯
|
|
213
|
+
# I/O 等待,3 个 worker 装不下更多 URL,预算会全花在排队上(见 evidence_loop)。
|
|
213
214
|
from evidence_loop import _verify_budget_s
|
|
214
215
|
budget_s = _verify_budget_s()
|
|
215
216
|
|
|
@@ -220,7 +221,7 @@ def numeric_verify_results(results: list[dict[str, Any]],
|
|
|
220
221
|
elif budget_s > 0 and len(targets) > 1:
|
|
221
222
|
from bounded_run import TaskError, run_bounded
|
|
222
223
|
finished, unfinished = run_bounded(
|
|
223
|
-
targets, _fetch_one, budget_s, max_workers=min(len(targets),
|
|
224
|
+
targets, _fetch_one, budget_s, max_workers=min(len(targets), 6))
|
|
224
225
|
for item, value in finished:
|
|
225
226
|
if isinstance(value, TaskError):
|
|
226
227
|
pending.append(item[0].get("url") or "")
|
|
@@ -240,18 +241,27 @@ def numeric_verify_results(results: list[dict[str, Any]],
|
|
|
240
241
|
# 顺序固定为 export 契约(调用方按这些键读 summary);词表值来自
|
|
241
242
|
# engine_states,键序留在这里。
|
|
242
243
|
counts = {v: 0 for v in VERDICTS}
|
|
244
|
+
from evidence_grounding import extract_anchored_context
|
|
245
|
+
|
|
243
246
|
for r, nums, val in outcomes:
|
|
244
247
|
page, method = val
|
|
248
|
+
anchored: list[dict[str, Any]] = []
|
|
245
249
|
if not page or len(page.strip()) < 100:
|
|
246
250
|
# 正文过短:无数可比,不伪造 verdict(unfetchable,不惩罚)
|
|
247
251
|
verdict, hits, misses = (
|
|
248
252
|
engine_states.NUMERIC_UNFETCHABLE, [], [n["raw"] for n in nums])
|
|
249
253
|
else:
|
|
250
254
|
verdict, hits, misses = _verdict_for(nums, page)
|
|
255
|
+
entity_hint = (query or "").strip() or str(r.get("title") or "")[:40]
|
|
256
|
+
for h in hits[:3]:
|
|
257
|
+
ctx = extract_anchored_context(page, h, entity=entity_hint)
|
|
258
|
+
if ctx.get("excerpt"):
|
|
259
|
+
anchored.append({"value": h, **ctx})
|
|
251
260
|
counts[verdict] += 1
|
|
252
261
|
r["numeric_verification"] = {
|
|
253
262
|
"verdict": verdict,
|
|
254
263
|
"checked": [n["raw"] for n in nums],
|
|
264
|
+
**({"anchored_excerpts": anchored} if anchored else {}),
|
|
255
265
|
"hits": hits,
|
|
256
266
|
"misses": misses,
|
|
257
267
|
"fetch_method": method,
|
|
@@ -112,6 +112,9 @@ def build_failures(result: dict[str, Any], limit: int = 6) -> list[dict[str, Any
|
|
|
112
112
|
# 周期边界前不会因重试改变。标出来,避免 Agent 立刻重试同一个源。
|
|
113
113
|
if status.startswith(engine_states.OUTCOME_SKIPPED_PREFIX):
|
|
114
114
|
item["persistent"] = True
|
|
115
|
+
if o.get("http_status") is not None:
|
|
116
|
+
# 原始 HTTP 状态码(403/404/429…):语义 status 之外的事实层
|
|
117
|
+
item["http_status"] = o.get("http_status")
|
|
115
118
|
detail = str(o.get("detail") or "").strip()
|
|
116
119
|
if detail:
|
|
117
120
|
item["detail"] = detail[:160]
|
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
|
@@ -220,11 +220,9 @@ class QuotaManager:
|
|
|
220
220
|
_PERIOD_SECONDS = {"hour": 3600, "day": 86400, "month": 30 * 86400}
|
|
221
221
|
|
|
222
222
|
def __init__(self):
|
|
223
|
-
self._lock = threading.
|
|
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
|
"""只判「月度预算是否用完」,不看次数/限频/远端配额。
|
|
@@ -773,34 +755,35 @@ class QuotaManager:
|
|
|
773
755
|
|
|
774
756
|
def get_stats(self) -> dict:
|
|
775
757
|
"""获取所有引擎的配额统计。"""
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
758
|
+
with self._lock:
|
|
759
|
+
self._fresh_locked()
|
|
760
|
+
stats = {}
|
|
761
|
+
for engine, profile in list(self._profiles.items()):
|
|
762
|
+
if engine.startswith("_") or not isinstance(profile, dict):
|
|
763
|
+
continue
|
|
764
|
+
# 残缺状态防御:state JSON 手工编辑/截断时 mark 可能非 dict,
|
|
765
|
+
# 与 _refresh_remote_state_locked 的 .get 计算方式保持一致
|
|
766
|
+
raw_mark = (self._state.get(engine) or {}).get("remote_exhausted")
|
|
767
|
+
mark = raw_mark if isinstance(raw_mark, dict) else None
|
|
768
|
+
stats[engine] = {
|
|
769
|
+
"remaining_ratio": round(self.get_remaining_ratio(engine), 2),
|
|
770
|
+
"rpm": self.get_current_rpm(engine),
|
|
771
|
+
"error_rate": round(self.get_error_rate(engine), 3),
|
|
772
|
+
"available": self.is_available(engine),
|
|
773
|
+
"cost_per_call": self.get_cost_per_call(engine),
|
|
774
|
+
"total_cost": round(self.get_total_cost(engine), 6),
|
|
775
|
+
"used": self._state.get(engine, {}).get("used", 0),
|
|
776
|
+
"limit": profile.get("limit", "∞"),
|
|
777
|
+
"period": profile.get("period"),
|
|
778
|
+
# 月度预算(原生币种):amount=None 表示未设预算、沿用次数额度
|
|
779
|
+
"budget": profile.get("budget_amount"),
|
|
780
|
+
"budget_currency": profile.get("budget_currency"),
|
|
781
|
+
"cost_used": round((self._state.get(engine) or {}).get("cost_used", 0.0), 6),
|
|
782
|
+
"cost_tier": profile.get("cost_tier", "free"),
|
|
783
|
+
"remote_exhausted_until": (
|
|
784
|
+
round(float(mark["until"])) if mark else None),
|
|
785
|
+
}
|
|
786
|
+
return stats
|
|
804
787
|
|
|
805
788
|
|
|
806
789
|
# ── 模块级单例 ─────────────────────────────────────────────────────────────────
|