argo-search 2.13.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +93 -0
- package/README.es.md +30 -8
- package/README.ja.md +30 -8
- package/README.ko.md +30 -8
- package/README.md +511 -596
- package/README.zh.md +975 -0
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/backends/domain_profiles.json +90 -6
- package/backends/engine_registry.yaml +222 -32
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +151 -11
- package/bin/argo +3 -0
- package/config.yaml +50 -4
- package/docs/CHANGELOG.md +45 -0
- package/docs/COMMIT_STANDARD.md +98 -0
- package/docs/ENGINE_CATALOG.md +100 -81
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.14.0.md +88 -0
- package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
- package/docs/RELEASING.md +52 -0
- package/engines/specs/artic.yaml +11 -1
- package/engines/specs/cleveland.yaml +15 -1
- package/engines/specs/clinicaltrials.yaml +24 -1
- package/engines/specs/cnii.yaml +17 -1
- package/engines/specs/coingecko.yaml +10 -2
- package/engines/specs/dbpedia.yaml +32 -0
- package/engines/specs/deezer.yaml +12 -1
- package/engines/specs/doaj.yaml +14 -1
- package/engines/specs/endoflife.yaml +16 -1
- package/engines/specs/eu_opendata.yaml +11 -1
- package/engines/specs/europeana.yaml +19 -1
- package/engines/specs/feed.yaml +62 -0
- package/engines/specs/figshare.yaml +12 -1
- package/engines/specs/fourget.yaml +23 -0
- package/engines/specs/grep_app.yaml +19 -0
- package/engines/specs/hackernews.yaml +17 -1
- package/engines/specs/hal.yaml +19 -1
- package/engines/specs/hf_datasets.yaml +59 -0
- package/engines/specs/hf_papers.yaml +42 -0
- package/engines/specs/jikan.yaml +12 -10
- package/engines/specs/kaggle.yaml +46 -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/maven.yaml +61 -0
- package/engines/specs/mojeek.yaml +31 -0
- package/engines/specs/mwmbl.yaml +39 -0
- package/engines/specs/nasa_cmr.yaml +12 -1
- package/engines/specs/nuget.yaml +57 -0
- package/engines/specs/openaire.yaml +34 -0
- package/engines/specs/repology.yaml +18 -0
- package/engines/specs/tatoeba.yaml +14 -1
- package/engines/specs/tvmaze.yaml +5 -1
- package/engines/specs/usda.yaml +14 -1
- package/package.json +14 -10
- package/packages/dsh-plugin/dsh/client.js +1 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +85 -116
- 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 +5 -3
- 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 +336 -19
- package/scripts/build_release_assets.sh +43 -15
- package/scripts/cache.py +3 -3
- package/scripts/check_commit_report.py +168 -0
- package/scripts/dormant_ledger.py +225 -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 +398 -8
- package/scripts/engine_status.py +31 -0
- package/scripts/engine_validate.py +224 -40
- package/scripts/engines.py +4 -34
- package/scripts/engines_base.py +53 -147
- package/scripts/engines_builders.py +2 -33
- package/scripts/engines_builders_batch12.py +168 -0
- package/scripts/engines_builders_batch16.py +13 -0
- package/scripts/engines_builders_batch9.py +0 -204
- package/scripts/engines_builders_feeds.py +148 -30
- package/scripts/engines_builders_intl.py +0 -328
- package/scripts/engines_builders_science.py +0 -85
- package/scripts/engines_builders_tech.py +0 -98
- package/scripts/engines_parsers.py +924 -0
- package/scripts/evidence_loop.py +91 -4
- package/scripts/fetch_browser.py +4 -2
- package/scripts/fetch_jsrun.py +2 -1
- package/scripts/fetch_v3.py +22 -22
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/gen_native_tools.py +46 -18
- package/scripts/local_intent.py +175 -0
- package/scripts/local_seek.py +256 -91
- package/scripts/local_seek_adapter.py +87 -0
- package/scripts/mcp_handlers.py +124 -72
- package/scripts/mcp_server.py +1 -1
- package/scripts/mcp_tools.py +143 -61
- package/scripts/mcp_transport.py +42 -10
- package/scripts/pre-commit +68 -1
- package/scripts/recovery.py +14 -5
- package/scripts/recovery_l0.py +5 -3
- package/scripts/release.py +20 -11
- package/scripts/release_check.py +1 -1
- 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 +26 -14
- package/scripts/search.py +33 -25
- package/scripts/search_cli.py +52 -6
- package/scripts/search_output.py +83 -16
- package/scripts/secret_guard.py +106 -0
- package/scripts/semantic_evidence.py +230 -15
- package/scripts/settings_page.py +80 -8
- package/scripts/source_audit.py +408 -0
- package/scripts/sync_backends.py +38 -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 +28 -9
- package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
- package/README.en.md +0 -814
- package/engines/specs/cinii.yaml +0 -44
- package/scripts/image_vision/vision_probe +0 -0
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
|
-
r
|
|
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
|
+
r'(?i)(?:\b(?:def|class|function|fn|import|export|const|var|struct|enum)\b|\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|sql|conf|cfg|ini|log)\b|(?:readme|config|package\.json|cargo\.toml|dockerfile|makefile|pyproject\.toml|tsconfig\.json|go\.mod|requirements\.txt|Cargo\.lock|\.gitignore|\.env)|\b[A-Za-z0-9_]+(?:Error|Exception|Fault)\b|\b(?:User|Deprecation|Runtime|Future|Syntax|Resource|Import)Warning\b|\b_[a-zA-Z0-9_]{2,}\b|\b[a-zA-Z_][a-zA-Z0-9_]*\((?!\s*(?:[0-9]+|[a-zA-Z])\s*\))[^\)]*\)|(?:本工程|本项目|代码库|本地文件|本地脚本|脚本文件|架构实现|函数|方法|源码|接口定义|本机|本地代码|本地笔记|我的文件|我的笔记|我的电脑|我的代码|仓库里|仓库中|工程里|项目里|当前目录|工作目录|\.agents/skills|\.obsidian))')
|
|
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,108 @@ 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
|
+
_CACHED_TARGETED_ROOTS: tuple[tuple[str, ...], float, list[str]] | None = None
|
|
321
|
+
# 缓存有效期(秒)。为什么需要 TTL:缓存键只含环境变量,不含文件系统状态——
|
|
322
|
+
# 进程内新建 ~/notes 这类标准根时,无 TTL 的缓存会让新目录在整个进程生命
|
|
323
|
+
# 周期内都不可见(实测)。60s 是「同一轮检索内不重复探测」与「新目录能较快
|
|
324
|
+
# 生效」的折中:检索是多目标串行的,单轮耗时远小于 60s,跨轮则能感知变化。
|
|
325
|
+
_TARGETED_ROOTS_CACHE_TTL_S = 60.0
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def _candidate_targeted_roots() -> list[str]:
|
|
329
|
+
"""宽泛根场景下的定向检索候选目录(既防全盘扫崩,又避免漏掉核心私域资产)。
|
|
330
|
+
|
|
331
|
+
彻底消除特定机器/个人工作区硬编码(如 Documents/GPT),优先环境变量覆盖,
|
|
332
|
+
自适应感知云端/容器工作区与跨平台 Agent 技能规范。
|
|
333
|
+
带环境变量感知与 TTL 的轻量缓存,消除每轮检索重复的文件系统 isdir/realpath
|
|
334
|
+
探测,同时不把新建目录锁死在进程生命周期内。
|
|
335
|
+
"""
|
|
336
|
+
global _CACHED_TARGETED_ROOTS
|
|
337
|
+
env_key = (
|
|
338
|
+
os.environ.get("ARGO_LOCAL_SEEK_ROOTS", ""),
|
|
339
|
+
os.environ.get("WORKSPACE", ""),
|
|
340
|
+
os.environ.get("PROJECT_DIR", ""),
|
|
341
|
+
os.environ.get("CI_PROJECT_DIR", ""),
|
|
342
|
+
)
|
|
343
|
+
if (_CACHED_TARGETED_ROOTS is not None
|
|
344
|
+
and _CACHED_TARGETED_ROOTS[0] == env_key
|
|
345
|
+
and time.time() - _CACHED_TARGETED_ROOTS[1] < _TARGETED_ROOTS_CACHE_TTL_S):
|
|
346
|
+
return list(_CACHED_TARGETED_ROOTS[2])
|
|
347
|
+
|
|
348
|
+
raw = env_key[0].strip()
|
|
349
|
+
if raw:
|
|
350
|
+
cands = [p for p in re.split(r"[:;]", raw) if p.strip()]
|
|
351
|
+
valid_roots = [c for c in cands if os.path.isdir(c) and not _is_own_install_root(c) and not _is_broad_local_root(c)]
|
|
352
|
+
_CACHED_TARGETED_ROOTS = (env_key, time.time(), list(valid_roots))
|
|
353
|
+
return valid_roots
|
|
354
|
+
|
|
355
|
+
cands: list[str] = []
|
|
356
|
+
|
|
357
|
+
# 1. 容器与 CI/CD 环境工作区感知(Docker / K8s / Cloud Shell)
|
|
358
|
+
for env_var in ("WORKSPACE", "PROJECT_DIR", "CI_PROJECT_DIR"):
|
|
359
|
+
v = os.environ.get(env_var, "").strip()
|
|
360
|
+
if v and os.path.isdir(v):
|
|
361
|
+
cands.append(v)
|
|
362
|
+
for container_root in ("/workspace", "/app", "/project"):
|
|
363
|
+
if os.path.isdir(container_root):
|
|
364
|
+
cands.append(container_root)
|
|
365
|
+
|
|
366
|
+
# 2. 跨平台通用标准私域目录(基于用户 home 规范派生,零特定主机字面量)
|
|
367
|
+
home = os.path.realpath(os.path.expanduser("~"))
|
|
368
|
+
standard_roots = [
|
|
369
|
+
os.path.join(home, ".agents", "skills"), # Agent Skills 行业规范目录
|
|
370
|
+
os.path.join(home, ".claude", "skills"), # Claude 客户端规范目录
|
|
371
|
+
os.path.join(home, ".codex", "skills"), # Codex 客户端规范目录
|
|
372
|
+
os.path.join(home, "workspace"), # 通用工作区目录
|
|
373
|
+
os.path.join(home, "projects"), # 通用工程目录
|
|
374
|
+
os.path.join(home, "notes"), # 通用笔记目录
|
|
375
|
+
]
|
|
376
|
+
cands.extend(standard_roots)
|
|
377
|
+
|
|
378
|
+
seen = set()
|
|
379
|
+
valid_roots = []
|
|
380
|
+
for c in cands:
|
|
381
|
+
try:
|
|
382
|
+
real_c = os.path.realpath(os.path.expanduser(c))
|
|
383
|
+
except OSError:
|
|
384
|
+
continue
|
|
385
|
+
if real_c in seen:
|
|
386
|
+
continue
|
|
387
|
+
seen.add(real_c)
|
|
388
|
+
if os.path.isdir(real_c) and not _is_broad_local_root(real_c) and not _is_own_install_root(real_c):
|
|
389
|
+
valid_roots.append(real_c)
|
|
390
|
+
_CACHED_TARGETED_ROOTS = (env_key, time.time(), list(valid_roots))
|
|
391
|
+
return valid_roots
|
|
251
392
|
|
|
252
393
|
|
|
253
394
|
def _run_local_seek(query: str, max_n: int = 5,
|
|
@@ -255,83 +396,102 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
255
396
|
warn: bool = True, echo: bool = True) -> list[dict[str, Any]]:
|
|
256
397
|
"""本机文件命中(include-local 用):进程内调 seek.run_query,JSON 并入。
|
|
257
398
|
|
|
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 条),告警改为结构化字段随响应返回。
|
|
399
|
+
双轨并发支持:非宽泛根搜当前项目;处于宽泛根时定向扫描高频私域目录。
|
|
266
400
|
"""
|
|
401
|
+
global _LAST_LOCAL_SEEK_MS, _LAST_LOCAL_SEEK_COUNT, _LAST_LOCAL_SEEK_SKIPPED
|
|
402
|
+
# 用 time.time 而非 perf_counter:本模块的时间源是 time(TTL 判定、
|
|
403
|
+
# 落盘缓存共用),换钟会让「耗时」与「缓存新鲜度」在测试冻结时钟时
|
|
404
|
+
# 分叉(test_b4_knobs 的 _FrozenClock 只冻 time)。差值语义不变。
|
|
405
|
+
_t0 = time.time()
|
|
406
|
+
_LAST_LOCAL_SEEK_SKIPPED = False
|
|
267
407
|
target = search_dir or _local_seek_dir()
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
# 占位「结果」又会污染 results(它只是个说明,不是命中),所以
|
|
273
|
-
# 说明走告警通道(stderr + 响应的 warnings[])。
|
|
274
|
-
# 只在**显式开启**时提示(warn=False 是 fast/budget 的自动路径):
|
|
275
|
-
# 自动路径在 home 等宽根下每次 search 都会打印,Agent 会把它当成
|
|
276
|
-
# 输出的一部分,属于噪音而非归因。
|
|
408
|
+
is_targeted_fallback = not target
|
|
409
|
+
targets = [target] if target else _candidate_targeted_roots()
|
|
410
|
+
if not targets:
|
|
411
|
+
_LAST_LOCAL_SEEK_SKIPPED = True
|
|
277
412
|
if warn:
|
|
278
413
|
_note_warning(
|
|
279
|
-
" [include-local]
|
|
280
|
-
"
|
|
281
|
-
"要搜本机文件请 cd 到目标目录后重试,或用 local-seek 的 seek.py --path <目录>",
|
|
414
|
+
" [include-local] 当前目录处于宽泛根且未发现预设私域资产目录,已跳过本地检索;"
|
|
415
|
+
"要搜特定目录请指定 --path 或切换到目标目录重试",
|
|
282
416
|
echo)
|
|
417
|
+
_LAST_LOCAL_SEEK_MS = int((time.time() - _t0) * 1000)
|
|
283
418
|
return []
|
|
284
419
|
|
|
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 明令禁止)。
|
|
420
|
+
# seek.py 存在性检查**下沉到缓存未命中分支**(2026-11-10):缓存命中不
|
|
421
|
+
# 需要 seek.py——把检查前置会让「子技能未装/工具暂时缺失」时 TTL 内的缓存
|
|
422
|
+
# 结果也拿不到,而缓存的全部意义正是省掉工具调用。前置检查还让
|
|
423
|
+
# test_b4_knobs 的进程内缓存 TTL 用例无法验证(它故意 mock 掉 seek.py
|
|
424
|
+
# 来短路真检索,结果连缓存都读不到)。
|
|
304
425
|
from seek_locator import resolve_seek_py
|
|
305
426
|
seek_py = resolve_seek_py()
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
427
|
+
_seek_py_ok = bool(seek_py) and os.path.isfile(seek_py)
|
|
428
|
+
|
|
429
|
+
combined_hits: list[dict[str, Any]] = []
|
|
430
|
+
seen_urls: set[str] = set()
|
|
431
|
+
_cap = min(max_n, _max_local_hits())
|
|
432
|
+
|
|
433
|
+
# 宽泛根定向私域回退时的总体时间预算(0.35s),防止多目标串行拖累整次搜索
|
|
434
|
+
_targeted_deadline = (_t0 + 0.35) if is_targeted_fallback else None
|
|
435
|
+
|
|
436
|
+
for tgt in targets:
|
|
437
|
+
if _targeted_deadline and time.time() >= _targeted_deadline:
|
|
438
|
+
break
|
|
439
|
+
cache_key = f"{query}|{max_n}|{tgt}"
|
|
440
|
+
cached = _LOCAL_SEEK_CACHE.get(cache_key)
|
|
441
|
+
if cached is not None and time.time() - cached[0] < _LOCAL_SEEK_TTL_S:
|
|
442
|
+
hits = cached[1]
|
|
443
|
+
else:
|
|
444
|
+
disk_hit = _seek_disk_cache_get(cache_key)
|
|
445
|
+
if disk_hit is not None:
|
|
446
|
+
if len(_LOCAL_SEEK_CACHE) >= _LOCAL_SEEK_CACHE_MAX:
|
|
447
|
+
_LOCAL_SEEK_CACHE.clear()
|
|
448
|
+
_LOCAL_SEEK_CACHE[cache_key] = (time.time(), disk_hit)
|
|
449
|
+
hits = disk_hit
|
|
450
|
+
else:
|
|
451
|
+
if not _seek_py_ok:
|
|
452
|
+
# 缓存未命中 + 工具缺失:本次无法检索(缓存已是最后手段)。
|
|
453
|
+
# 不在这里 return——多目标场景下其余目标可能仍有缓存。
|
|
454
|
+
continue
|
|
455
|
+
payload = None
|
|
456
|
+
_budget = (min(_LOCAL_SEEK_TIMEOUT_S, max(0.1, _targeted_deadline - time.time()))
|
|
457
|
+
if _targeted_deadline else _LOCAL_SEEK_TIMEOUT_S)
|
|
458
|
+
try:
|
|
459
|
+
payload = seek_query_payload(query, tgt, max_n,
|
|
460
|
+
time_budget=_budget,
|
|
461
|
+
warn=warn, echo=echo)
|
|
462
|
+
except Exception:
|
|
463
|
+
payload = None
|
|
464
|
+
if payload is None:
|
|
465
|
+
payload = _seek_query_subprocess(seek_py, query, tgt, max_n)
|
|
466
|
+
if payload is None or payload.get("_error"):
|
|
467
|
+
hits = []
|
|
468
|
+
else:
|
|
469
|
+
hits = _payload_to_hits(payload, max_n, cache_key)
|
|
470
|
+
_seek_disk_cache_put(cache_key, hits)
|
|
471
|
+
|
|
472
|
+
for h in hits:
|
|
473
|
+
u = h.get("url")
|
|
474
|
+
if u not in seen_urls:
|
|
475
|
+
seen_urls.add(u)
|
|
476
|
+
combined_hits.append(h)
|
|
477
|
+
if len(combined_hits) >= _cap:
|
|
478
|
+
break
|
|
479
|
+
if len(combined_hits) >= _cap:
|
|
480
|
+
break
|
|
481
|
+
|
|
482
|
+
# 工具缺失且**所有**目标都无缓存命中:此时确实是「检索未执行」,必须
|
|
483
|
+
# 留可归因说明(不能与「查了没有」同形)。缓存命中的目标不算——它们
|
|
484
|
+
# 已经交付了结果,只是没走工具。
|
|
485
|
+
if not _seek_py_ok and not combined_hits:
|
|
486
|
+
_LAST_LOCAL_SEEK_SKIPPED = True
|
|
310
487
|
if warn:
|
|
311
488
|
_note_warning(
|
|
312
|
-
" [include-local] 未找到 local-seek 的 seek.py
|
|
313
|
-
"
|
|
314
|
-
return []
|
|
489
|
+
" [include-local] 未找到 local-seek 的 seek.py 且无缓存命中,"
|
|
490
|
+
"本机文件检索未执行", echo)
|
|
315
491
|
|
|
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
|
|
492
|
+
_LAST_LOCAL_SEEK_MS = int((time.time() - _t0) * 1000)
|
|
493
|
+
_LAST_LOCAL_SEEK_COUNT = len(combined_hits)
|
|
494
|
+
return combined_hits[:_cap]
|
|
335
495
|
|
|
336
496
|
|
|
337
497
|
def _load_seek_module(seek_py: str):
|
|
@@ -428,8 +588,7 @@ def _seek_query_subprocess(seek_py: str, query: str, target: str,
|
|
|
428
588
|
|
|
429
589
|
def _payload_to_hits(payload: dict[str, Any], max_n: int,
|
|
430
590
|
cache_key: str) -> list[dict[str, Any]]:
|
|
431
|
-
"""seek payload → include-local
|
|
432
|
-
同口径:0.9 精确命中 / 0.7 扩展召回),并写入进程内缓存。"""
|
|
591
|
+
"""seek payload → include-local 结果条目(明确来源标记)。"""
|
|
433
592
|
hits = payload.get("results") or payload.get("files") or []
|
|
434
593
|
seek_mode = payload.get("mode", "fast")
|
|
435
594
|
hit_score = 0.9 if seek_mode == "fast" else 0.7
|
|
@@ -439,12 +598,18 @@ def _payload_to_hits(payload: dict[str, Any], max_n: int,
|
|
|
439
598
|
continue
|
|
440
599
|
path = h.get("path") or h.get("file") or ""
|
|
441
600
|
line = h.get("line") or h.get("lineno") or 1
|
|
442
|
-
|
|
601
|
+
line_str = f":{line}" if str(line).isdigit() and int(line) > 0 else ""
|
|
602
|
+
url = f"file://{path}" + (f"#{line}" if str(line).isdigit() and int(line) > 0 else "")
|
|
603
|
+
title = f"[本机] {path}{line_str}"
|
|
604
|
+
snippet = (h.get("snippet") or h.get("text") or h.get("line_text") or "")[:200]
|
|
443
605
|
out.append({
|
|
444
|
-
"title":
|
|
606
|
+
"title": title,
|
|
445
607
|
"url": url,
|
|
446
|
-
"snippet":
|
|
608
|
+
"snippet": f"[本机文件] {snippet}" if not snippet.startswith("[本机") else snippet,
|
|
447
609
|
"source": "local_files",
|
|
610
|
+
"source_type": "local",
|
|
611
|
+
"channel": "local_filesystem",
|
|
612
|
+
"is_local": True,
|
|
448
613
|
"score": hit_score,
|
|
449
614
|
"kind": "local",
|
|
450
615
|
})
|
|
@@ -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())
|