argo-search 2.13.0 → 2.14.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 +93 -0
- package/README.en.md +16 -4
- package/README.es.md +16 -4
- package/README.ja.md +16 -4
- package/README.ko.md +16 -4
- package/README.md +16 -4
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/backends/domain_profiles.json +66 -6
- package/backends/engine_registry.yaml +154 -15
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +111 -11
- package/bin/argo +3 -0
- package/config.yaml +27 -1
- package/docs/CHANGELOG.md +23 -0
- package/docs/COMMIT_STANDARD.md +98 -0
- package/docs/ENGINE_CATALOG.md +94 -79
- package/docs/RELEASE_NOTES_v2.14.0.md +77 -0
- package/engines/specs/clinicaltrials.yaml +8 -0
- package/engines/specs/cnii.yaml +5 -0
- package/engines/specs/coingecko.yaml +10 -2
- package/engines/specs/dbpedia.yaml +32 -0
- package/engines/specs/fourget.yaml +23 -0
- package/engines/specs/grep_app.yaml +19 -0
- package/engines/specs/hackernews.yaml +1 -0
- package/engines/specs/hf_papers.yaml +26 -0
- package/engines/specs/kaggle.yaml +44 -0
- package/engines/specs/local_baidu.yaml +5 -0
- package/engines/specs/local_seek.yaml +34 -0
- package/engines/specs/local_yandex.yaml +37 -0
- package/engines/specs/mojeek.yaml +31 -0
- package/engines/specs/mwmbl.yaml +39 -0
- package/engines/specs/openaire.yaml +34 -0
- package/engines/specs/repology.yaml +18 -0
- package/package.json +13 -10
- package/packages/dsh-plugin/dsh/client.js +1 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +24 -3
- package/packages/dsh-plugin/dsh/runner.js +35 -1
- package/packages/dsh-plugin/dsh/specs.js +3 -1
- package/packages/dsh-plugin/dsh/wide-research.js +4 -2
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/client.test.js +6 -0
- package/packages/dsh-plugin/test/config.test.js +5 -1
- package/packages/dsh-plugin/test/index.test.js +3 -1
- package/packages/dsh-plugin/test/size-gate.test.js +2 -2
- package/scripts/badcase_causes.py +81 -0
- package/scripts/badcase_ledger.py +287 -14
- package/scripts/cache.py +3 -3
- package/scripts/check_commit_report.py +168 -0
- package/scripts/engine_admission.py +9 -5
- package/scripts/engine_families.py +13 -2
- package/scripts/engine_policy.py +1 -1
- package/scripts/engine_states.py +393 -8
- package/scripts/engine_status.py +31 -0
- package/scripts/engine_validate.py +47 -39
- package/scripts/engines.py +6 -0
- package/scripts/engines_base.py +26 -80
- package/scripts/engines_builders.py +5 -0
- package/scripts/engines_builders_batch12.py +168 -0
- package/scripts/engines_builders_batch16.py +186 -0
- package/scripts/engines_parsers.py +399 -0
- package/scripts/fetch_browser.py +4 -2
- package/scripts/fetch_jsrun.py +2 -1
- package/scripts/fetch_v3.py +22 -22
- package/scripts/gen_native_tools.py +44 -17
- package/scripts/local_intent.py +139 -0
- package/scripts/local_seek.py +223 -91
- package/scripts/local_seek_adapter.py +87 -0
- package/scripts/mcp_transport.py +1 -1
- package/scripts/pre-commit +44 -1
- package/scripts/recovery.py +14 -5
- package/scripts/recovery_l0.py +5 -3
- package/scripts/research.py +1 -1
- package/scripts/research_gates.py +3 -3
- package/scripts/route_lang.py +6 -1
- package/scripts/route_policy.py +21 -14
- package/scripts/search.py +33 -25
- package/scripts/search_cli.py +10 -1
- package/scripts/search_output.py +83 -16
- package/scripts/source_audit.py +331 -0
- package/scripts/sync_backends.py +31 -1
- package/scripts/wechat_article.py +5 -3
- package/scripts/wide_research.py +4 -1
- package/scripts/x_article_fetch.py +2 -1
- package/sub-skills/local-search/parsers.py +6 -1
- package/sub-skills/local-seek/scripts/seek.py +390 -24
- package/sub-skills/local-seek/scripts/seek_fts.py +20 -9
- package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
- package/engines/specs/cinii.yaml +0 -44
package/scripts/local_seek.py
CHANGED
|
@@ -31,6 +31,49 @@ from typing import Any
|
|
|
31
31
|
# 本地命中是尾部增强项,不是主结果,它的等待不配与搜索引擎同等。
|
|
32
32
|
_LOCAL_SEEK_TIMEOUT_S = 3.0
|
|
33
33
|
|
|
34
|
+
# 最近一次本机检索的耗时与命中数(毫秒级可观测性,进程内单槽)。
|
|
35
|
+
# 写侧在 _run_local_seek 收口;读侧由 search.py 在搜索收尾时取走并
|
|
36
|
+
# 写进 usage_log 的 query 流——「本地检索实际花了多久、带回几条」此前
|
|
37
|
+
# 只能靠猜,现在有账。
|
|
38
|
+
_LAST_LOCAL_SEEK_MS = 0
|
|
39
|
+
_LAST_LOCAL_SEEK_COUNT = 0
|
|
40
|
+
_LAST_LOCAL_SEEK_SKIPPED = False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def local_seek_last_ms() -> int:
|
|
44
|
+
return _LAST_LOCAL_SEEK_MS
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def local_seek_last_count() -> int:
|
|
48
|
+
return _LAST_LOCAL_SEEK_COUNT
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def local_seek_last_skipped() -> bool:
|
|
52
|
+
return _LAST_LOCAL_SEEK_SKIPPED
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def local_seek_accounting() -> dict[str, Any]:
|
|
56
|
+
"""最近一次本机检索的账(读侧唯一入口)。
|
|
57
|
+
|
|
58
|
+
返回 {} 表示本地轨本次没跑(宽根无候选 / seek.py 缺失 / 被意图预判
|
|
59
|
+
跳过)——空字典与「跑了但 0 命中」在语义上不同,调用方据此决定是否
|
|
60
|
+
写日志字段。字段与 usage_log 的 local_seek 流、响应里的
|
|
61
|
+
local_seek_ms / local_seek_count / local_seek_skipped 三键同口径。
|
|
62
|
+
"""
|
|
63
|
+
if _LAST_LOCAL_SEEK_SKIPPED:
|
|
64
|
+
return {"local_seek_skipped": True}
|
|
65
|
+
return {
|
|
66
|
+
"local_seek_ms": _LAST_LOCAL_SEEK_MS,
|
|
67
|
+
"local_seek_count": _LAST_LOCAL_SEEK_COUNT,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# 本机命中条数上限:本地命中是尾部增强项,不该挤压公网结果的排序位置。
|
|
71
|
+
# 调用方传入的 max_n 是「本次搜索总结果数」,而本地命中并入后会与公网结果
|
|
72
|
+
# 争抢同一个 results 列表;设一个固定上限(而非按 n 比例)让本地命中的
|
|
73
|
+
# 占比在 n 变大时自然收缩——n=10 时本地仍最多 3 条,公网结果保住主体。
|
|
74
|
+
# 可用 ARGO_LOCAL_SEEK_MAX_HITS 覆盖。
|
|
75
|
+
_LOCAL_SEEK_MAX_HITS = 3
|
|
76
|
+
|
|
34
77
|
# 搜索期告警(issue #34 第 4/7 条):--json 模式下 stderr 会被调用方
|
|
35
78
|
# 2>&1 合并,任何中文告警行都会破坏 JSON 解析。告警统一进这个列表,
|
|
36
79
|
# search.py 组装完响应后 drain 并作为 warnings[] 字段随 JSON 返回;
|
|
@@ -172,12 +215,10 @@ def _seek_disk_cache_put(key: str, results: list[dict[str, Any]]) -> None:
|
|
|
172
215
|
|
|
173
216
|
|
|
174
217
|
# 本地代码/工程/配置意图正则模式
|
|
218
|
+
# 判据与 local_intent._LOCAL_SIGNAL_RE 逐字一致(红绿锁见
|
|
219
|
+
# tests/test_local_intent.py::test_intent_pattern_matches_local_seek)。
|
|
175
220
|
_LOCAL_INTENT_PATTERN = re.compile(
|
|
176
|
-
|
|
177
|
-
r"\.(?:py|js|ts|json|yaml|yml|md|rs|go|c|cpp|h|sh|sql)\b|"
|
|
178
|
-
r"(?:readme|config|package\.json|cargo\.toml|dockerfile|makefile)|"
|
|
179
|
-
r"(?:本工程|本项目|代码库|本地文件|架构实现|函数|方法|源码|接口定义))"
|
|
180
|
-
)
|
|
221
|
+
'(?i)(?:\\b(?:def|class|function|fn|import|export|const|var|struct|enum)\\b|\\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|sql|conf|cfg|ini|log)\\b|(?:readme|config|package\\.json|cargo\\.toml|dockerfile|makefile|pyproject\\.toml|tsconfig\\.json|go\\.mod|requirements\\.txt|Cargo\\.lock|\\.gitignore|\\.env)|\\b[A-Za-z0-9_]+(?:Error|Exception|Fault|Warning)\\b|\\b_[a-zA-Z0-9_]{2,}\\b|\\b[a-zA-Z0-9_]+\\([^\\)]*\\)|(?:本工程|本项目|代码库|本地文件|本地脚本|脚本文件|架构实现|函数|方法|源码|接口定义|本机|本地代码|本地笔记|我的文件|我的笔记|我的电脑|我的代码|仓库里|仓库中|工程里|项目里|当前目录|工作目录|\\.agents/skills|\\.obsidian))')
|
|
181
222
|
|
|
182
223
|
|
|
183
224
|
def has_local_code_intent(query: str) -> bool:
|
|
@@ -187,20 +228,31 @@ def has_local_code_intent(query: str) -> bool:
|
|
|
187
228
|
return bool(_LOCAL_INTENT_PATTERN.search(query))
|
|
188
229
|
|
|
189
230
|
|
|
190
|
-
def resolve_include_local(include_local: bool | None, mode: str, query: str = ""
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
自适应感知:除 fast/budget 模式外,当查询具有明显的本地代码/文件特征
|
|
194
|
-
且处于非宽泛根项目目录时,自动开启本地命中。
|
|
195
|
-
"""
|
|
231
|
+
def resolve_include_local(include_local: bool | None, mode: str, query: str = "",
|
|
232
|
+
domain: str | None = None) -> bool:
|
|
233
|
+
"""include-local 三态解析:True/False 显式,None=信号驱动。"""
|
|
196
234
|
if include_local is not None:
|
|
197
235
|
return bool(include_local)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
236
|
+
try:
|
|
237
|
+
from local_intent import should_run_local_by_signal, should_skip_local
|
|
238
|
+
if should_skip_local(domain, query):
|
|
239
|
+
return False
|
|
240
|
+
if should_run_local_by_signal(query, domain):
|
|
241
|
+
return True
|
|
242
|
+
except Exception:
|
|
243
|
+
pass # 判据失败 fail-open:宁可多搜一次本地,也不误杀
|
|
202
244
|
return False
|
|
203
245
|
|
|
246
|
+
def _max_local_hits() -> int:
|
|
247
|
+
"""本机命中条数上限(ARGO_LOCAL_SEEK_MAX_HITS 可覆盖)。"""
|
|
248
|
+
try:
|
|
249
|
+
raw = os.environ.get("ARGO_LOCAL_SEEK_MAX_HITS")
|
|
250
|
+
if raw is not None and raw.strip() != "":
|
|
251
|
+
return max(0, int(raw))
|
|
252
|
+
except (TypeError, ValueError):
|
|
253
|
+
pass
|
|
254
|
+
return _LOCAL_SEEK_MAX_HITS
|
|
255
|
+
|
|
204
256
|
|
|
205
257
|
def _is_broad_local_root(path: str) -> bool:
|
|
206
258
|
"""path 是否是「不能当作本地检索范围」的宽泛根。
|
|
@@ -235,19 +287,83 @@ def _is_own_install_root(path: str) -> bool:
|
|
|
235
287
|
return real == _OWN_INSTALL_ROOT or real.startswith(_OWN_INSTALL_ROOT + os.sep)
|
|
236
288
|
|
|
237
289
|
|
|
290
|
+
def _detect_project_root(start_dir: str | None = None) -> str | None:
|
|
291
|
+
"""从当前目录向上回溯探测工程根目录(根据 .git / 常见项目清单识别)。
|
|
292
|
+
|
|
293
|
+
避免用户在项目深度子目录执行检索时,因范围过窄漏掉顶层架构文档与同级模块。
|
|
294
|
+
"""
|
|
295
|
+
try:
|
|
296
|
+
cur = Path(start_dir or os.getcwd()).resolve()
|
|
297
|
+
markers = {".git", "pyproject.toml", "package.json", "Cargo.toml", "go.mod"}
|
|
298
|
+
for parent in [cur] + list(cur.parents):
|
|
299
|
+
if any((parent / m).exists() for m in markers):
|
|
300
|
+
p_str = str(parent)
|
|
301
|
+
if not _is_broad_local_root(p_str) and not _is_own_install_root(p_str):
|
|
302
|
+
return p_str
|
|
303
|
+
except Exception:
|
|
304
|
+
pass
|
|
305
|
+
return None
|
|
306
|
+
|
|
307
|
+
|
|
238
308
|
def _local_seek_dir() -> str | None:
|
|
239
309
|
"""本地检索的适用范围;宽泛根或自身安装树返回 None(据此跳过本地命中)。
|
|
240
310
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
用户想搜特定树时 cd 到目标目录,或用 local-seek 的 seek.py 显式给
|
|
244
|
-
--path(网络类查询另有 argo search --local-first 走本地引擎聚合),
|
|
245
|
-
那条路径不受此守卫影响。
|
|
311
|
+
当前处于某个具体工程或其子目录时,优先自适应溯源至工程根(覆盖全局文档);
|
|
312
|
+
若处于宽泛根或自身安装树则返回 None,由调用方进入定向私域资产探测。
|
|
246
313
|
"""
|
|
247
314
|
cwd = os.getcwd()
|
|
248
315
|
if _is_broad_local_root(cwd) or _is_own_install_root(cwd):
|
|
249
316
|
return None
|
|
250
|
-
return cwd
|
|
317
|
+
return _detect_project_root(cwd) or cwd
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _candidate_targeted_roots() -> list[str]:
|
|
321
|
+
"""宽泛根场景下的定向检索候选目录(既防全盘扫崩,又避免漏掉核心私域资产)。
|
|
322
|
+
|
|
323
|
+
彻底消除特定机器/个人工作区硬编码(如 Documents/GPT),优先环境变量覆盖,
|
|
324
|
+
自适应感知云端/容器工作区与跨平台 Agent 技能规范。
|
|
325
|
+
"""
|
|
326
|
+
raw = os.environ.get("ARGO_LOCAL_SEEK_ROOTS", "").strip()
|
|
327
|
+
if raw:
|
|
328
|
+
cands = [p for p in re.split(r"[:;]", raw) if p.strip()]
|
|
329
|
+
return [c for c in cands if os.path.isdir(c) and not _is_own_install_root(c) and not _is_broad_local_root(c)]
|
|
330
|
+
|
|
331
|
+
cands: list[str] = []
|
|
332
|
+
|
|
333
|
+
# 1. 容器与 CI/CD 环境工作区感知(Docker / K8s / Cloud Shell)
|
|
334
|
+
for env_var in ("WORKSPACE", "PROJECT_DIR", "CI_PROJECT_DIR"):
|
|
335
|
+
v = os.environ.get(env_var, "").strip()
|
|
336
|
+
if v and os.path.isdir(v):
|
|
337
|
+
cands.append(v)
|
|
338
|
+
for container_root in ("/workspace", "/app", "/project"):
|
|
339
|
+
if os.path.isdir(container_root):
|
|
340
|
+
cands.append(container_root)
|
|
341
|
+
|
|
342
|
+
# 2. 跨平台通用标准私域目录(基于用户 home 规范派生,零特定主机字面量)
|
|
343
|
+
home = os.path.realpath(os.path.expanduser("~"))
|
|
344
|
+
standard_roots = [
|
|
345
|
+
os.path.join(home, ".agents", "skills"), # Agent Skills 行业规范目录
|
|
346
|
+
os.path.join(home, ".claude", "skills"), # Claude 客户端规范目录
|
|
347
|
+
os.path.join(home, ".codex", "skills"), # Codex 客户端规范目录
|
|
348
|
+
os.path.join(home, "workspace"), # 通用工作区目录
|
|
349
|
+
os.path.join(home, "projects"), # 通用工程目录
|
|
350
|
+
os.path.join(home, "notes"), # 通用笔记目录
|
|
351
|
+
]
|
|
352
|
+
cands.extend(standard_roots)
|
|
353
|
+
|
|
354
|
+
seen = set()
|
|
355
|
+
valid_roots = []
|
|
356
|
+
for c in cands:
|
|
357
|
+
try:
|
|
358
|
+
real_c = os.path.realpath(os.path.expanduser(c))
|
|
359
|
+
except OSError:
|
|
360
|
+
continue
|
|
361
|
+
if real_c in seen:
|
|
362
|
+
continue
|
|
363
|
+
seen.add(real_c)
|
|
364
|
+
if os.path.isdir(real_c) and not _is_broad_local_root(real_c) and not _is_own_install_root(real_c):
|
|
365
|
+
valid_roots.append(real_c)
|
|
366
|
+
return valid_roots
|
|
251
367
|
|
|
252
368
|
|
|
253
369
|
def _run_local_seek(query: str, max_n: int = 5,
|
|
@@ -255,83 +371,94 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
255
371
|
warn: bool = True, echo: bool = True) -> list[dict[str, Any]]:
|
|
256
372
|
"""本机文件命中(include-local 用):进程内调 seek.run_query,JSON 并入。
|
|
257
373
|
|
|
258
|
-
|
|
259
|
-
auto/deep 需显式 --include-local / MCP include_local。评分与
|
|
260
|
-
MCP argo_local_search 同口径(0.9 精确 / 0.7 扩展)。
|
|
261
|
-
进程内失败回退子进程形态(_seek_query_subprocess),能力不回退。
|
|
262
|
-
|
|
263
|
-
echo=False 时告警不写 stderr,只进 drain_search_warnings()——`--json`
|
|
264
|
-
模式的调用方把 2>&1 合并成管道时,stderr 上的中文行会破坏 JSON 解析
|
|
265
|
-
(issue #34 第 7 条),告警改为结构化字段随响应返回。
|
|
374
|
+
双轨并发支持:非宽泛根搜当前项目;处于宽泛根时定向扫描高频私域目录。
|
|
266
375
|
"""
|
|
376
|
+
global _LAST_LOCAL_SEEK_MS, _LAST_LOCAL_SEEK_COUNT, _LAST_LOCAL_SEEK_SKIPPED
|
|
377
|
+
# 用 time.time 而非 perf_counter:本模块的时间源是 time(TTL 判定、
|
|
378
|
+
# 落盘缓存共用),换钟会让「耗时」与「缓存新鲜度」在测试冻结时钟时
|
|
379
|
+
# 分叉(test_b4_knobs 的 _FrozenClock 只冻 time)。差值语义不变。
|
|
380
|
+
_t0 = time.time()
|
|
381
|
+
_LAST_LOCAL_SEEK_SKIPPED = False
|
|
267
382
|
target = search_dir or _local_seek_dir()
|
|
268
|
-
if
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
# 静默跳过会让用户以为本地没匹配,而事实是根本没查。返回一个
|
|
272
|
-
# 占位「结果」又会污染 results(它只是个说明,不是命中),所以
|
|
273
|
-
# 说明走告警通道(stderr + 响应的 warnings[])。
|
|
274
|
-
# 只在**显式开启**时提示(warn=False 是 fast/budget 的自动路径):
|
|
275
|
-
# 自动路径在 home 等宽根下每次 search 都会打印,Agent 会把它当成
|
|
276
|
-
# 输出的一部分,属于噪音而非归因。
|
|
383
|
+
targets = [target] if target else _candidate_targeted_roots()
|
|
384
|
+
if not targets:
|
|
385
|
+
_LAST_LOCAL_SEEK_SKIPPED = True
|
|
277
386
|
if warn:
|
|
278
387
|
_note_warning(
|
|
279
|
-
" [include-local]
|
|
280
|
-
"
|
|
281
|
-
"要搜本机文件请 cd 到目标目录后重试,或用 local-seek 的 seek.py --path <目录>",
|
|
388
|
+
" [include-local] 当前目录处于宽泛根且未发现预设私域资产目录,已跳过本地检索;"
|
|
389
|
+
"要搜特定目录请指定 --path 或切换到目标目录重试",
|
|
282
390
|
echo)
|
|
391
|
+
_LAST_LOCAL_SEEK_MS = int((time.time() - _t0) * 1000)
|
|
283
392
|
return []
|
|
284
393
|
|
|
285
|
-
#
|
|
286
|
-
#
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return cached[1]
|
|
291
|
-
|
|
292
|
-
# H3:跨进程落盘缓存(CLI 每次新进程,进程内缓存救不了 CLI 重复查询;
|
|
293
|
-
# MCP 常驻进程通常在内存层就命中,落盘层对它是兜底)。命中后回填内存层。
|
|
294
|
-
disk_hit = _seek_disk_cache_get(cache_key)
|
|
295
|
-
if disk_hit is not None:
|
|
296
|
-
if len(_LOCAL_SEEK_CACHE) >= _LOCAL_SEEK_CACHE_MAX:
|
|
297
|
-
_LOCAL_SEEK_CACHE.clear()
|
|
298
|
-
_LOCAL_SEEK_CACHE[cache_key] = (time.time(), disk_hit)
|
|
299
|
-
return disk_hit
|
|
300
|
-
|
|
301
|
-
# 安装感知 + 唯一来源:委托 seek_locator 统一发现 local-seek/scripts/seek.py
|
|
302
|
-
# (打包子技能优先,ARGO_LOCAL_SEEK_PATH / ARGO_LOCAL_SEEK_ROOTS 承载自定义/遗留)。
|
|
303
|
-
# 不硬编码 ~/.agents/skills|~/.claude/skills 主机路径(SKILL.md 明令禁止)。
|
|
394
|
+
# seek.py 存在性检查**下沉到缓存未命中分支**(2026-11-10):缓存命中不
|
|
395
|
+
# 需要 seek.py——把检查前置会让「子技能未装/工具暂时缺失」时 TTL 内的缓存
|
|
396
|
+
# 结果也拿不到,而缓存的全部意义正是省掉工具调用。前置检查还让
|
|
397
|
+
# test_b4_knobs 的进程内缓存 TTL 用例无法验证(它故意 mock 掉 seek.py
|
|
398
|
+
# 来短路真检索,结果连缓存都读不到)。
|
|
304
399
|
from seek_locator import resolve_seek_py
|
|
305
400
|
seek_py = resolve_seek_py()
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
401
|
+
_seek_py_ok = bool(seek_py) and os.path.isfile(seek_py)
|
|
402
|
+
|
|
403
|
+
combined_hits: list[dict[str, Any]] = []
|
|
404
|
+
seen_urls: set[str] = set()
|
|
405
|
+
_cap = min(max_n, _max_local_hits())
|
|
406
|
+
|
|
407
|
+
for tgt in targets:
|
|
408
|
+
cache_key = f"{query}|{max_n}|{tgt}"
|
|
409
|
+
cached = _LOCAL_SEEK_CACHE.get(cache_key)
|
|
410
|
+
if cached is not None and time.time() - cached[0] < _LOCAL_SEEK_TTL_S:
|
|
411
|
+
hits = cached[1]
|
|
412
|
+
else:
|
|
413
|
+
disk_hit = _seek_disk_cache_get(cache_key)
|
|
414
|
+
if disk_hit is not None:
|
|
415
|
+
if len(_LOCAL_SEEK_CACHE) >= _LOCAL_SEEK_CACHE_MAX:
|
|
416
|
+
_LOCAL_SEEK_CACHE.clear()
|
|
417
|
+
_LOCAL_SEEK_CACHE[cache_key] = (time.time(), disk_hit)
|
|
418
|
+
hits = disk_hit
|
|
419
|
+
else:
|
|
420
|
+
if not _seek_py_ok:
|
|
421
|
+
# 缓存未命中 + 工具缺失:本次无法检索(缓存已是最后手段)。
|
|
422
|
+
# 不在这里 return——多目标场景下其余目标可能仍有缓存。
|
|
423
|
+
continue
|
|
424
|
+
payload = None
|
|
425
|
+
try:
|
|
426
|
+
payload = seek_query_payload(query, tgt, max_n,
|
|
427
|
+
time_budget=_LOCAL_SEEK_TIMEOUT_S,
|
|
428
|
+
warn=warn, echo=echo)
|
|
429
|
+
except Exception:
|
|
430
|
+
payload = None
|
|
431
|
+
if payload is None:
|
|
432
|
+
payload = _seek_query_subprocess(seek_py, query, tgt, max_n)
|
|
433
|
+
if payload is None or payload.get("_error"):
|
|
434
|
+
hits = []
|
|
435
|
+
else:
|
|
436
|
+
hits = _payload_to_hits(payload, max_n, cache_key)
|
|
437
|
+
_seek_disk_cache_put(cache_key, hits)
|
|
438
|
+
|
|
439
|
+
for h in hits:
|
|
440
|
+
u = h.get("url")
|
|
441
|
+
if u not in seen_urls:
|
|
442
|
+
seen_urls.add(u)
|
|
443
|
+
combined_hits.append(h)
|
|
444
|
+
if len(combined_hits) >= _cap:
|
|
445
|
+
break
|
|
446
|
+
if len(combined_hits) >= _cap:
|
|
447
|
+
break
|
|
448
|
+
|
|
449
|
+
# 工具缺失且**所有**目标都无缓存命中:此时确实是「检索未执行」,必须
|
|
450
|
+
# 留可归因说明(不能与「查了没有」同形)。缓存命中的目标不算——它们
|
|
451
|
+
# 已经交付了结果,只是没走工具。
|
|
452
|
+
if not _seek_py_ok and not combined_hits:
|
|
453
|
+
_LAST_LOCAL_SEEK_SKIPPED = True
|
|
310
454
|
if warn:
|
|
311
455
|
_note_warning(
|
|
312
|
-
" [include-local] 未找到 local-seek 的 seek.py
|
|
313
|
-
"
|
|
314
|
-
return []
|
|
456
|
+
" [include-local] 未找到 local-seek 的 seek.py 且无缓存命中,"
|
|
457
|
+
"本机文件检索未执行", echo)
|
|
315
458
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
# 内部 rg/fd 子进程(子进程可硬杀,线程不可杀——不传会占死单线程 executor)。
|
|
320
|
-
# 进程内失败(模块加载/执行异常)回退子进程路径:能力不回退,只是慢。
|
|
321
|
-
payload = None
|
|
322
|
-
try:
|
|
323
|
-
payload = seek_query_payload(query, target, max_n,
|
|
324
|
-
time_budget=_LOCAL_SEEK_TIMEOUT_S,
|
|
325
|
-
warn=warn, echo=echo)
|
|
326
|
-
except Exception:
|
|
327
|
-
payload = None
|
|
328
|
-
if payload is None:
|
|
329
|
-
payload = _seek_query_subprocess(seek_py, query, target, max_n)
|
|
330
|
-
if payload is None or payload.get("_error"):
|
|
331
|
-
return []
|
|
332
|
-
out = _payload_to_hits(payload, max_n, cache_key)
|
|
333
|
-
_seek_disk_cache_put(cache_key, out) # H3:写穿到落盘层
|
|
334
|
-
return out
|
|
459
|
+
_LAST_LOCAL_SEEK_MS = int((time.time() - _t0) * 1000)
|
|
460
|
+
_LAST_LOCAL_SEEK_COUNT = len(combined_hits)
|
|
461
|
+
return combined_hits[:_cap]
|
|
335
462
|
|
|
336
463
|
|
|
337
464
|
def _load_seek_module(seek_py: str):
|
|
@@ -428,8 +555,7 @@ def _seek_query_subprocess(seek_py: str, query: str, target: str,
|
|
|
428
555
|
|
|
429
556
|
def _payload_to_hits(payload: dict[str, Any], max_n: int,
|
|
430
557
|
cache_key: str) -> list[dict[str, Any]]:
|
|
431
|
-
"""seek payload → include-local
|
|
432
|
-
同口径:0.9 精确命中 / 0.7 扩展召回),并写入进程内缓存。"""
|
|
558
|
+
"""seek payload → include-local 结果条目(明确来源标记)。"""
|
|
433
559
|
hits = payload.get("results") or payload.get("files") or []
|
|
434
560
|
seek_mode = payload.get("mode", "fast")
|
|
435
561
|
hit_score = 0.9 if seek_mode == "fast" else 0.7
|
|
@@ -439,12 +565,18 @@ def _payload_to_hits(payload: dict[str, Any], max_n: int,
|
|
|
439
565
|
continue
|
|
440
566
|
path = h.get("path") or h.get("file") or ""
|
|
441
567
|
line = h.get("line") or h.get("lineno") or 1
|
|
442
|
-
|
|
568
|
+
line_str = f":{line}" if str(line).isdigit() and int(line) > 0 else ""
|
|
569
|
+
url = f"file://{path}" + (f"#{line}" if str(line).isdigit() and int(line) > 0 else "")
|
|
570
|
+
title = f"[本机] {path}{line_str}"
|
|
571
|
+
snippet = (h.get("snippet") or h.get("text") or h.get("line_text") or "")[:200]
|
|
443
572
|
out.append({
|
|
444
|
-
"title":
|
|
573
|
+
"title": title,
|
|
445
574
|
"url": url,
|
|
446
|
-
"snippet":
|
|
575
|
+
"snippet": f"[本机文件] {snippet}" if not snippet.startswith("[本机") else snippet,
|
|
447
576
|
"source": "local_files",
|
|
577
|
+
"source_type": "local",
|
|
578
|
+
"channel": "local_filesystem",
|
|
579
|
+
"is_local": True,
|
|
448
580
|
"score": hit_score,
|
|
449
581
|
"kind": "local",
|
|
450
582
|
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""seek.py → argo CLI 桥接适配器(跨平台兼容与来源隔离)。
|
|
3
|
+
|
|
4
|
+
1. 来源隔离:严格标注 [本机] 前缀、source_type='local'、channel='local_filesystem'、
|
|
5
|
+
is_local=True,生成规范 file:// URI,杜绝与公网/联网搜索结果混淆。
|
|
6
|
+
2. 跨平台开箱即用:显式 utf-8 管道编码,防 Windows GBK 控制台乱码;Path.resolve().as_uri()
|
|
7
|
+
同时支持 Windows 驱动器盘符与 POSIX 路径;提供进程内 run_query 容错降级。
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
SEEK_DIR = Path(__file__).resolve().parent.parent / "sub-skills" / "local-seek" / "scripts"
|
|
18
|
+
SEEK = SEEK_DIR / "seek.py"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _run_seek(argv: list[str]) -> dict:
|
|
22
|
+
"""运行 seek.py,优先子进程隔离,受限环境降级为进程内调用。"""
|
|
23
|
+
try:
|
|
24
|
+
proc = subprocess.run(
|
|
25
|
+
[sys.executable, str(SEEK), *argv, "--json"],
|
|
26
|
+
capture_output=True, text=True, timeout=60,
|
|
27
|
+
encoding="utf-8", errors="replace",
|
|
28
|
+
)
|
|
29
|
+
if proc.returncode == 0 and proc.stdout:
|
|
30
|
+
return json.loads(proc.stdout)
|
|
31
|
+
except (subprocess.TimeoutExpired, ValueError, OSError):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
# 进程内容错降级
|
|
35
|
+
try:
|
|
36
|
+
if str(SEEK_DIR) not in sys.path:
|
|
37
|
+
sys.path.insert(0, str(SEEK_DIR))
|
|
38
|
+
import seek as seek_mod
|
|
39
|
+
text, rc = seek_mod.run_query([*argv, "--json"], time_budget=30.0)
|
|
40
|
+
if rc == 0 and text:
|
|
41
|
+
return json.loads(text)
|
|
42
|
+
except Exception:
|
|
43
|
+
pass
|
|
44
|
+
return {}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main() -> int:
|
|
48
|
+
argv = [a for a in sys.argv[1:] if a != "--json"]
|
|
49
|
+
data = _run_seek(argv)
|
|
50
|
+
|
|
51
|
+
base = data.get("path") or "."
|
|
52
|
+
out: list[dict] = []
|
|
53
|
+
base_path = Path(base).resolve()
|
|
54
|
+
|
|
55
|
+
for r in data.get("results", []):
|
|
56
|
+
if not isinstance(r, dict):
|
|
57
|
+
continue
|
|
58
|
+
p = str(r.get("path") or "")
|
|
59
|
+
line = r.get("line")
|
|
60
|
+
snippet = str(r.get("snippet") or "")[:300]
|
|
61
|
+
# 来源显式隔离标识:明确标记为 [本机]
|
|
62
|
+
title_loc = f"{p}:{line}" if line else p
|
|
63
|
+
row: dict = {
|
|
64
|
+
"title": f"[本机] {title_loc}",
|
|
65
|
+
"snippet": f"[本机文件] {snippet}" if not snippet.startswith("[本机") else snippet,
|
|
66
|
+
"source_type": "local",
|
|
67
|
+
"channel": "local_filesystem",
|
|
68
|
+
"is_local": True,
|
|
69
|
+
"engine": "local_seek",
|
|
70
|
+
}
|
|
71
|
+
if p:
|
|
72
|
+
try:
|
|
73
|
+
abs_p = (base_path / p).resolve()
|
|
74
|
+
row["url"] = abs_p.as_uri()
|
|
75
|
+
except (ValueError, OSError):
|
|
76
|
+
norm_p = p.replace("\\", "/")
|
|
77
|
+
row["url"] = f"file:///{norm_p.lstrip('/')}"
|
|
78
|
+
if r.get("mtime"):
|
|
79
|
+
row["published_at"] = str(r["mtime"])
|
|
80
|
+
out.append(row)
|
|
81
|
+
|
|
82
|
+
print(json.dumps({"results": out}, ensure_ascii=False))
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
raise SystemExit(main())
|
package/scripts/mcp_transport.py
CHANGED
package/scripts/pre-commit
CHANGED
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
# 一律红灯——290d3d8 同根因累计 9 处灭类后零祖父,AST 扫描 <0.5s)。
|
|
18
18
|
# dependency_source(2026-11-09 补:pyproject 是真源、requirements 是派生清单,
|
|
19
19
|
# 双向对账——清单里有真源没有的、真源里有 lock 没有的,都红。实测 <0.5s)。
|
|
20
|
+
# 状态词表四件套(2026-11-10 补):test_engine_states(词表契约)、
|
|
21
|
+
# test_native_tools_sync(Python→JS 生成物漂移)、test_zcode_bridge_daemon_state
|
|
22
|
+
# (桥的 daemon 状态读字段)、test_state_literal_drift(AST 扫「已登记状态值
|
|
23
|
+
# 又退回去写成字面量」)。此前改 engine_states.py 不跑全量 pytest 就能提交,
|
|
24
|
+
# hook 与 CI 都没有这几道门;四者合计 <1s,放进 hook 不触发 --no-verify 绕过。
|
|
20
25
|
# 2026-10-18 补的两道(context_budget + engine_catalog):f702ee2 把
|
|
21
26
|
# SKILL.md 压到 8049B、4a71693 让 deepseek_search 成死源,两笔都过了 hook
|
|
22
27
|
# 却在全量回归里红——正是「改完没跑到那条门」的同一个洞。全量回归 ~5 分钟
|
|
@@ -94,8 +99,46 @@ printf "[pre-commit] argo 快门禁(~13s,解释器 %s;全量回归请手
|
|
|
94
99
|
tests/test_launch_passthrough_alignment.py \
|
|
95
100
|
tests/test_dependency_source_gate.py \
|
|
96
101
|
tests/test_install_script_contract.py \
|
|
97
|
-
tests/test_deep_budget_tail_grace.py
|
|
102
|
+
tests/test_deep_budget_tail_grace.py \
|
|
103
|
+
tests/test_engine_states.py \
|
|
104
|
+
tests/test_native_tools_sync.py \
|
|
105
|
+
tests/test_zcode_bridge_daemon_state.py \
|
|
106
|
+
tests/test_state_literal_drift.py \
|
|
107
|
+
tests/test_check_commit_report.py \
|
|
108
|
+
tests/test_badcase_ledger.py \
|
|
109
|
+
tests/test_agents_routing.py
|
|
110
|
+
|
|
111
|
+
# 派生件一致性门禁(P0-2):写完 spec 不跑 sync 就提交,派生件会过期。
|
|
112
|
+
# 实测 0.13s,进 pre-commit 不触发 --no-verify 绕过。
|
|
113
|
+
echo "[pre-commit] 派生件一致性校验..."
|
|
114
|
+
if ! "$PY" scripts/sync_backends.py --check; then
|
|
115
|
+
echo "[pre-commit] 派生件过期,请运行: python3 scripts/sync_backends.py" >&2
|
|
116
|
+
exit 1
|
|
117
|
+
fi
|
|
98
118
|
|
|
99
119
|
if command -v node >/dev/null 2>&1 && [ -f packages/dsh-plugin/test/size-gate.test.js ]; then
|
|
100
120
|
node --test packages/dsh-plugin/test/size-gate.test.js packages/dsh-plugin/test/client.test.js
|
|
101
121
|
fi
|
|
122
|
+
|
|
123
|
+
# 高风险提交的检查清单提示(2026-11-10):只警告不硬拦。
|
|
124
|
+
# 为什么只警告:hook 慢于 20s 就会被 --no-verify 绕过,一道会被绕过的硬门
|
|
125
|
+
# 比没有门更坏(见本文件头 2026-10-18 的注释)。它只让「省略未跑检查」变可见。
|
|
126
|
+
#
|
|
127
|
+
# EDITMSG 的位置与时机:worktree 根目录或 git-common-dir(后者给 linked
|
|
128
|
+
# worktree)。**pre-commit 阶段该文件可能还是上一次提交的内容**——git 在 hook
|
|
129
|
+
# 跑完后才把新信息写进去。所以这里比对文件内容与 HEAD 的提交信息:相同就说明
|
|
130
|
+
# 读到的是旧稿,跳过本次提示(不是每个提交都需要它,为它把提交卡住本末倒置)。
|
|
131
|
+
_editmsg=""
|
|
132
|
+
_git_common=$(git rev-parse --git-common-dir 2>/dev/null || true)
|
|
133
|
+
for _cand in "$root/COMMIT_EDITMSG" "$_git_common/COMMIT_EDITMSG"; do
|
|
134
|
+
case "$_cand" in
|
|
135
|
+
*/COMMIT_EDITMSG) [ -f "$_cand" ] && { _editmsg="$_cand"; break; } ;;
|
|
136
|
+
esac
|
|
137
|
+
done
|
|
138
|
+
if [ -n "$_editmsg" ]; then
|
|
139
|
+
_head_subject=$(git log -1 --format=%s HEAD 2>/dev/null || true)
|
|
140
|
+
_draft_subject=$(grep -v '^#' "$_editmsg" 2>/dev/null | grep -v '^[[:space:]]*$' | head -1 || true)
|
|
141
|
+
if [ -n "$_draft_subject" ] && [ "$_draft_subject" != "$_head_subject" ]; then
|
|
142
|
+
"$PY" scripts/check_commit_report.py --message-file "$_editmsg" || true
|
|
143
|
+
fi
|
|
144
|
+
fi
|
package/scripts/recovery.py
CHANGED
|
@@ -31,6 +31,7 @@ from pathlib import Path
|
|
|
31
31
|
from typing import Any, Callable, Optional
|
|
32
32
|
|
|
33
33
|
from cjk_tokens import signal_tokens
|
|
34
|
+
import engine_states
|
|
34
35
|
|
|
35
36
|
_BACKENDS_DIR = Path(__file__).parent.parent / "backends"
|
|
36
37
|
_SYNONYMS_PATH = _BACKENDS_DIR / "query_synonyms_cn.json"
|
|
@@ -532,13 +533,21 @@ def build_recovery_plan(query: str, tried_engines: list[str],
|
|
|
532
533
|
|
|
533
534
|
# fast 模式:仅保留 L1 + L3
|
|
534
535
|
if mode == "fast":
|
|
535
|
-
steps = [s for s in steps if s.level in
|
|
536
|
+
steps = [s for s in steps if s.level in engine_states.RECOVERY_FAST_LEVELS]
|
|
536
537
|
|
|
537
|
-
# 复杂度门控:low 查询只保留低成本放宽(L1/L2),禁高价多源/跨语言(L3/L4
|
|
538
|
+
# 复杂度门控:low 查询只保留低成本放宽(L1/L2),禁高价多源/跨语言(L3/L4)。
|
|
539
|
+
# 词表见 engine_states §23:L0 是恢复车道专用,成本序 -1;未登记的
|
|
540
|
+
# max_level 一律 fail-closed 返回空计划,绝不能回退到最高档 3(旧实现
|
|
541
|
+
# `.get(..., 3)` 让 max_level="L0" 放行全部高价策略,门控形同虚设)。
|
|
538
542
|
if max_level:
|
|
539
|
-
|
|
540
|
-
cut
|
|
541
|
-
|
|
543
|
+
cut = engine_states.recovery_level_tier(max_level)
|
|
544
|
+
if cut is None:
|
|
545
|
+
return []
|
|
546
|
+
# 步骤等级同样 fail-closed:未登记等级一律剔除,不用 `or 0` 把
|
|
547
|
+
# None 当 L1 放行(那会重演本条注释要堵的静默回退)。
|
|
548
|
+
steps = [s for s in steps
|
|
549
|
+
if (tier := engine_states.recovery_level_tier(s.level)) is not None
|
|
550
|
+
and tier <= cut]
|
|
542
551
|
|
|
543
552
|
return steps
|
|
544
553
|
|
package/scripts/recovery_l0.py
CHANGED
|
@@ -26,6 +26,8 @@ L0 是恢复决策树的第 0 级:补跑本 combo 的 skipped 引擎,非空
|
|
|
26
26
|
|
|
27
27
|
from __future__ import annotations
|
|
28
28
|
|
|
29
|
+
import engine_states
|
|
30
|
+
|
|
29
31
|
import time
|
|
30
32
|
from typing import Any, Callable
|
|
31
33
|
|
|
@@ -131,10 +133,10 @@ def maybe_retry_skipped(
|
|
|
131
133
|
info = {
|
|
132
134
|
"triggered": True,
|
|
133
135
|
"recovered": True,
|
|
134
|
-
"level_used":
|
|
136
|
+
"level_used": engine_states.RECOVERY_LEVEL_L0,
|
|
135
137
|
"strategy_used": "retry_skipped",
|
|
136
138
|
"steps_tried": [{
|
|
137
|
-
"level":
|
|
139
|
+
"level": engine_states.RECOVERY_LEVEL_L0,
|
|
138
140
|
"strategy": "retry_skipped",
|
|
139
141
|
"query": query,
|
|
140
142
|
"engines": skipped,
|
|
@@ -149,7 +151,7 @@ def maybe_retry_skipped(
|
|
|
149
151
|
"query": (query[:60] if query else query),
|
|
150
152
|
"triggered": True,
|
|
151
153
|
"recovered": True,
|
|
152
|
-
"level_used":
|
|
154
|
+
"level_used": engine_states.RECOVERY_LEVEL_L0,
|
|
153
155
|
"strategy_used": "retry_skipped",
|
|
154
156
|
"steps_tried": 1,
|
|
155
157
|
"final_query": (query[:60] if query else query),
|
package/scripts/research.py
CHANGED
|
@@ -43,7 +43,7 @@ _RESEARCH_EN_BOOSTS: tuple[str, ...] = ("octen", "anysearch", "github", "exa")
|
|
|
43
43
|
_RESEARCH_JA_KO_BOOSTS: tuple[str, ...] = ("anysearch", "local_bing")
|
|
44
44
|
_RESEARCH_ACADEMIC_BOOSTS: tuple[str, ...] = (
|
|
45
45
|
"semantic_scholar", "arxiv", "openalex", "crossref", "google_scholar",
|
|
46
|
-
"openreview", "biorxiv",
|
|
46
|
+
"openreview", "biorxiv", "openaire",
|
|
47
47
|
)
|
|
48
48
|
_ACADEMIC_QUERY_RE = re.compile(
|
|
49
49
|
r"(?i)(论文|文献|综述|引用网络|预印本|学术|期刊|会议论文|研究现状"
|
|
@@ -262,11 +262,11 @@ def evaluate_dossier_gates(dossier: dict[str, Any]) -> dict[str, Any]:
|
|
|
262
262
|
})
|
|
263
263
|
|
|
264
264
|
if failures:
|
|
265
|
-
cap =
|
|
265
|
+
cap = engine_states.CONCLUSION_CAP_LOW
|
|
266
266
|
elif warnings:
|
|
267
|
-
cap =
|
|
267
|
+
cap = engine_states.CONCLUSION_CAP_MEDIUM
|
|
268
268
|
else:
|
|
269
|
-
cap =
|
|
269
|
+
cap = engine_states.CONCLUSION_CAP_HIGH
|
|
270
270
|
|
|
271
271
|
return {
|
|
272
272
|
"passed": not failures,
|
package/scripts/route_lang.py
CHANGED
|
@@ -535,7 +535,12 @@ def _filter_lang_bound_family(combo: list[str], features: dict | None,
|
|
|
535
535
|
|
|
536
536
|
|
|
537
537
|
_LANG_EXCLUSIVE_ENGINES: frozenset[str] = frozenset({
|
|
538
|
-
"cinii"
|
|
538
|
+
# 2026-11-10:原写 "cinii"——那是同一源(cir.nii.ac.jp/opensearch/all)
|
|
539
|
+
# 的重复注册,没有专属 builder(type 是通用 http,engines._BUILDERS
|
|
540
|
+
# 查无此名),实际生效的一直是 "cnii"(type: cnii,自定义 builder)。
|
|
541
|
+
# 于是本表从未真正生效:英文/中文查询照样把日文源选进 academic 预算
|
|
542
|
+
# 窗口。已删 cinii spec,本表改为 "cnii"。
|
|
543
|
+
"cnii", # 日本学术总库(ja):中文/英文查询拿不到任何可用结果
|
|
539
544
|
})
|
|
540
545
|
|
|
541
546
|
|