argo-search 2.16.0 → 2.18.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 +4 -2
- package/README.es.md +15 -5
- package/README.ja.md +15 -5
- package/README.ko.md +15 -5
- package/README.md +16 -6
- package/README.zh.md +16 -6
- package/SKILL.md +12 -11
- 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 +121 -18
- package/backends/engine_registry.yaml +23 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +20 -0
- package/bin/argo +78 -12
- package/docs/CHANGELOG.md +35 -1
- package/docs/COMMIT_STANDARD.md +12 -2
- package/docs/ENGINE_CATALOG.md +36 -33
- package/docs/RELEASE_NOTES_v2.17.0.md +66 -0
- package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
- package/docs/RELEASING.md +2 -2
- 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/engines/specs/twitter_cli.yaml +17 -0
- package/engines/specs/twitter_syndication.yaml +2 -3
- 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 +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/native-tools.mjs +10 -0
- 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 +182 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +445 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +277 -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 +96 -0
- package/packages/dsh-plugin/test/workbench.test.js +422 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/affected_tests.py +324 -0
- package/scripts/badcase_ledger.py +93 -2
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +59 -9
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/cli_io.py +8 -3
- 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_families.py +1 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +54 -4
- package/scripts/engines.py +2 -0
- package/scripts/engines_base.py +19 -44
- package/scripts/engines_builders_intl.py +20 -94
- 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/engines_twitter_cli.py +182 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_cli_output.py +75 -0
- package/scripts/fetch_dispatch.py +248 -0
- package/scripts/fetch_quality.py +11 -0
- package/scripts/fetch_v3.py +48 -114
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/intent_router.py +224 -0
- package/scripts/mcp_compact.py +3 -0
- package/scripts/mcp_handlers.py +24 -4
- package/scripts/mcp_tools.py +2 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/mcp_warm.py +15 -11
- package/scripts/numeric_verify.py +9 -0
- package/scripts/output_transparency.py +10 -0
- package/scripts/pre-commit +65 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/release_check.py +1 -2
- package/scripts/research_gates.py +85 -1
- package/scripts/research_notes.py +52 -5
- package/scripts/retry_policy.py +17 -3
- package/scripts/route_combo.py +21 -4
- package/scripts/search.py +29 -29
- package/scripts/search_cli.py +104 -8
- package/scripts/search_output.py +4 -1
- package/scripts/social_research.py +8 -6
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/time_utils.py +28 -0
- package/scripts/twitter_single_read.py +107 -0
- package/scripts/x_keyword_route.py +138 -0
- package/scripts/x_search.py +24 -33
- package/scripts/zhihu_answer_body.py +96 -0
- package/scripts/zhihu_answer_fetch.py +66 -0
- package/scripts/zhihu_answer_lookup.py +138 -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/sub-skills/local-seek/SKILL.md +3 -1
- package/sub-skills/local-seek/scripts/seek.py +80 -109
- package/sub-skills/local-seek/scripts/seek_git.py +65 -0
- package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
|
@@ -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
|
|
package/scripts/release_check.py
CHANGED
|
@@ -38,8 +38,7 @@ import re
|
|
|
38
38
|
import sys
|
|
39
39
|
from pathlib import Path
|
|
40
40
|
|
|
41
|
-
#
|
|
42
|
-
# packages/argo-zcode 剥离,插件清单/面板 UI/插件市场三处声明同步退出)
|
|
41
|
+
# 八处机器声明的相对路径(顺序即报错输出顺序)
|
|
43
42
|
JSON_DECLS = (
|
|
44
43
|
"package.json",
|
|
45
44
|
"packages/dsh-plugin/package.json",
|
|
@@ -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
|
+
}
|
|
@@ -299,22 +299,64 @@ def create_explore_bundle(
|
|
|
299
299
|
)
|
|
300
300
|
|
|
301
301
|
|
|
302
|
+
def _parse_study_stdin(raw: str, pick: int = 0) -> dict[str, str]:
|
|
303
|
+
"""从 stdin JSON(argo fetch --json 或 argo search --agent)提取 study 参数。"""
|
|
304
|
+
payload = json.loads(raw)
|
|
305
|
+
if not isinstance(payload, dict):
|
|
306
|
+
raise ValueError("stdin JSON 必须是对象(来自 argo fetch --json 或 argo search --agent)")
|
|
307
|
+
# 形态 1:argo fetch --json
|
|
308
|
+
if payload.get("url") and ("content" in payload or "fetch_method" in payload):
|
|
309
|
+
return {
|
|
310
|
+
"url": str(payload.get("url") or "").strip(),
|
|
311
|
+
"title": str(payload.get("title") or "").strip(),
|
|
312
|
+
"archive_text": str(payload.get("content") or ""),
|
|
313
|
+
"related": "",
|
|
314
|
+
}
|
|
315
|
+
# 形态 2:argo search --agent / --json
|
|
316
|
+
results = payload.get("results")
|
|
317
|
+
if isinstance(results, list) and results:
|
|
318
|
+
idx = max(0, min(pick, len(results) - 1))
|
|
319
|
+
chosen = results[idx] if isinstance(results[idx], dict) else {}
|
|
320
|
+
others = [
|
|
321
|
+
str(r.get("url")) for i, r in enumerate(results)
|
|
322
|
+
if i != idx and isinstance(r, dict) and r.get("url")
|
|
323
|
+
]
|
|
324
|
+
return {
|
|
325
|
+
"url": str(chosen.get("url") or "").strip(),
|
|
326
|
+
"title": str(chosen.get("title") or "").strip(),
|
|
327
|
+
"archive_text": str(chosen.get("snippet") or ""),
|
|
328
|
+
"related": ", ".join(others[:5]),
|
|
329
|
+
}
|
|
330
|
+
raise ValueError("无法识别的 stdin JSON 结构:缺少 url/content 或 results[]")
|
|
331
|
+
|
|
332
|
+
|
|
302
333
|
def _cmd_create(args: argparse.Namespace) -> int:
|
|
303
334
|
kind = args.command
|
|
304
|
-
|
|
335
|
+
piped: dict[str, str] = {}
|
|
336
|
+
if kind == "study" and (not args.url or getattr(args, "from_json", False)):
|
|
337
|
+
from cli_io import stdin_is_memory_stream, stdin_is_piped
|
|
338
|
+
should_read = getattr(args, "from_json", False) or stdin_is_piped() or stdin_is_memory_stream()
|
|
339
|
+
raw = sys.stdin.read().strip() if should_read else ""
|
|
340
|
+
if raw:
|
|
341
|
+
piped = _parse_study_stdin(raw, pick=int(getattr(args, "pick", 0) or 0))
|
|
342
|
+
target = (args.url or piped.get("url") or "") if kind == "study" else args.problem
|
|
343
|
+
if not target:
|
|
344
|
+
raise SystemExit("study 需要提供 <url>,或通过管道传入 `argo fetch --json` / `argo search --agent` 输出")
|
|
305
345
|
slug = args.slug or slugify(target)
|
|
306
346
|
out_path = Path(args.output).expanduser().resolve() if args.output else None
|
|
307
347
|
archive_text = ""
|
|
308
348
|
if kind == "study":
|
|
309
|
-
archive_text = args.archive_text or ""
|
|
349
|
+
archive_text = args.archive_text or piped.get("archive_text") or ""
|
|
310
350
|
if not archive_text and args.archive and Path(args.archive).is_file():
|
|
311
351
|
try:
|
|
312
352
|
archive_text = Path(args.archive).read_text(encoding="utf-8", errors="replace")
|
|
313
353
|
except OSError:
|
|
314
354
|
pass
|
|
355
|
+
title = args.title or piped.get("title") or slug
|
|
356
|
+
related = args.related or piped.get("related") or "无"
|
|
315
357
|
res = _create_note_bundle(
|
|
316
|
-
kind, root=resolve_root(args.root), slug=slug, title=
|
|
317
|
-
target=target, related=
|
|
358
|
+
kind, root=resolve_root(args.root), slug=slug, title=title,
|
|
359
|
+
target=target, related=related,
|
|
318
360
|
archive_text=archive_text, output=out_path,
|
|
319
361
|
)
|
|
320
362
|
print(dumps(res))
|
|
@@ -339,7 +381,12 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
339
381
|
("explore", "problem", "探索问题或主题", "生成方向探索研报(标准 Markdown + Frontmatter)"),
|
|
340
382
|
):
|
|
341
383
|
sp = sub.add_parser(name, help=desc)
|
|
342
|
-
|
|
384
|
+
if name == "study":
|
|
385
|
+
sp.add_argument(arg_name, nargs="?", default="", help=f"{arg_help}(省略时从 stdin JSON 读取)")
|
|
386
|
+
sp.add_argument("--from-json", action="store_true", help="显式从 stdin 读取 fetch/search JSON 管道")
|
|
387
|
+
sp.add_argument("--pick", type=int, default=0, help="从 search JSON 的 results[] 中选取第 N 条(默认 0)")
|
|
388
|
+
else:
|
|
389
|
+
sp.add_argument(arg_name, help=arg_help)
|
|
343
390
|
sp.add_argument("--title", help="标题(缺省用 slug)")
|
|
344
391
|
sp.add_argument("--slug", help="标识符(缺省从对象推导)")
|
|
345
392
|
sp.add_argument("-o", "--output", help="直接指定研报输出文件路径")
|
package/scripts/retry_policy.py
CHANGED
|
@@ -28,6 +28,18 @@ _BLOCKED_ERROR_KEYWORDS = (
|
|
|
28
28
|
"just a moment", "checking your browser", "cf-browser-verification",
|
|
29
29
|
"challenge", "ddos-guard", "perimeterx", "access denied",
|
|
30
30
|
"handshake failure", "unable to handshake", "安全验证", "滑动验证",
|
|
31
|
+
"captcha", "cloudflare", "verify you are human",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# 瞬时网络 / 连接 / DNS / TLS / 服务端 5xx 错误(与超时同属 transient/network,可重试)
|
|
35
|
+
_TRANSIENT_ERROR_KEYWORDS = (
|
|
36
|
+
"timeout", "timed out", "connection reset", "connection refused",
|
|
37
|
+
"connection aborted", "remote disconnected", "eof occurred",
|
|
38
|
+
"broken pipe", "urlopen error", "getaddrinfo", "name or service not known",
|
|
39
|
+
"nodename nor servname", "network is unreachable", "temporary failure",
|
|
40
|
+
"ssl:", "certificate verify failed", "bad gateway", "service unavailable",
|
|
41
|
+
"gateway timeout", "internal server error", "http 500", "http 502",
|
|
42
|
+
"http 503", "http 504", " 500 ", " 502 ", " 503 ", " 504 ",
|
|
31
43
|
)
|
|
32
44
|
|
|
33
45
|
# 确定性失败:源端状态,不是网络抖动。重试只是多烧一次调用并推迟切备选
|
|
@@ -55,15 +67,17 @@ def classify_error_status(message: Any) -> str:
|
|
|
55
67
|
拦截是源端状态,鉴权最后(401/403 也可能来自拦截页)。
|
|
56
68
|
"""
|
|
57
69
|
m = str(message or "").lower()
|
|
58
|
-
|
|
70
|
+
padded = f" {m} "
|
|
71
|
+
if any(k in padded for k in _TRANSIENT_ERROR_KEYWORDS):
|
|
59
72
|
return engine_states.OUTCOME_TIMEOUT
|
|
60
73
|
if any(k in m for k in _QUOTA_ERROR_KEYWORDS):
|
|
61
74
|
return engine_states.OUTCOME_QUOTA_EXHAUSTED
|
|
62
|
-
if "rate" in m or "429" in m:
|
|
75
|
+
if "rate" in m or "429" in m or "too many requests" in m or "throttl" in m:
|
|
63
76
|
return engine_states.OUTCOME_RATE_LIMITED
|
|
64
77
|
if any(k in m for k in _BLOCKED_ERROR_KEYWORDS):
|
|
65
78
|
return engine_states.OUTCOME_BLOCKED
|
|
66
|
-
if "auth" in m or "401" in m or "403" in m
|
|
79
|
+
if ("auth" in m or "401" in m or "403" in m
|
|
80
|
+
or "unauthorized" in m or "invalid api key" in m or "invalid key" in m):
|
|
67
81
|
return engine_states.OUTCOME_AUTH_FAILED
|
|
68
82
|
return engine_states.OUTCOME_ERROR
|
|
69
83
|
|