papersearch 0.5.14 → 0.5.15
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/carsi/paper_search_carsi/adapters/base.py +3 -0
- package/carsi/paper_search_carsi/adapters/platforms/figshare/__init__.py +8 -2
- package/carsi/paper_search_carsi/assets/capsule.html +0 -1
- package/carsi/paper_search_carsi/engine/batch.py +13 -3
- package/carsi/paper_search_carsi/engine/bridge.py +15 -12
- package/carsi/paper_search_carsi/engine/page_supplements.py +67 -0
- package/carsi/paper_search_carsi/progress_view.py +0 -2
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +1 -1
- package/package.json +1 -1
- package/skills/paper-search/SKILL.md +1 -1
- package/skills/paper-search/references/browser-download.md +1 -1
- package/skills/paper-search/references/cli-contract.md +1 -1
- package/skills/paper-search/references/publisher-support.md +2 -2
|
@@ -16,6 +16,9 @@ class SupplementLink:
|
|
|
16
16
|
label: str = ""
|
|
17
17
|
# Discovery failures are recorded alongside downloaded files.
|
|
18
18
|
error: str = ""
|
|
19
|
+
# Found on the page but not shown to be this article's (a dataset the page
|
|
20
|
+
# only names): recorded with this reason, neither fetched nor counted.
|
|
21
|
+
set_aside: str = ""
|
|
19
22
|
|
|
20
23
|
|
|
21
24
|
class PublisherAdapter:
|
|
@@ -85,7 +85,8 @@ def _belongs(data: dict, doi: str, *, labelled: bool = False) -> bool:
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
def supplement_links(page: Any, doi: str, *, clock=time.monotonic, pause=time.sleep) -> list[SupplementLink] | None:
|
|
88
|
-
"""None means no Figshare route on this article; failures stay in the manifest.
|
|
88
|
+
"""None means no Figshare route on this article; failures stay in the manifest.
|
|
89
|
+
A resource not shown to be this article's is set aside (``set_aside``)."""
|
|
89
90
|
data = page.evaluate(_PAGE_LINKS)
|
|
90
91
|
if not isinstance(data, dict) or _doi(data.get("doi")) != _doi(doi):
|
|
91
92
|
return None
|
|
@@ -190,5 +191,10 @@ def supplement_links(page: Any, doi: str, *, clock=time.monotonic, pause=time.sl
|
|
|
190
191
|
raise
|
|
191
192
|
except Exception as exc:
|
|
192
193
|
reason = str(exc) if isinstance(exc, ValueError) and str(exc).startswith("figshare_") else "figshare_request_failed"
|
|
193
|
-
|
|
194
|
+
if reason == "figshare_article_mismatch":
|
|
195
|
+
# A dataset the article names (its data availability statement) is
|
|
196
|
+
# not its supplement unless one of them says so (JEM, 2026-11-11).
|
|
197
|
+
links.append(SupplementLink(root, "Figshare resource", set_aside=reason))
|
|
198
|
+
else:
|
|
199
|
+
links.append(SupplementLink(root, "Figshare supplementary material", error=reason))
|
|
194
200
|
return list(dict.fromkeys(links))
|
|
@@ -238,7 +238,7 @@ class PublisherBatchDownloader(
|
|
|
238
238
|
self._wait_for_page_text(page, result)
|
|
239
239
|
if self._challenge_shell(page) or self._is_challenge_page(page):
|
|
240
240
|
continue
|
|
241
|
-
links = self._settled_supplement_links(page, doi)
|
|
241
|
+
links = self._settled_supplement_links(page, doi, result)
|
|
242
242
|
if not (self._challenge_shell(page) or self._is_challenge_page(page)):
|
|
243
243
|
break
|
|
244
244
|
self._snapshot(page, result, "supplements page")
|
|
@@ -311,15 +311,25 @@ class PublisherBatchDownloader(
|
|
|
311
311
|
except Exception:
|
|
312
312
|
pass
|
|
313
313
|
|
|
314
|
-
def _settled_supplement_links(self, page: Any, doi: str) -> Any:
|
|
314
|
+
def _settled_supplement_links(self, page: Any, doi: str, result: Any = None) -> Any:
|
|
315
315
|
"""The adapter's links once the page has stopped navigating (ScienceDirect
|
|
316
|
-
moves /pii/ to /abs/pii/ by script after the document has loaded).
|
|
316
|
+
moves /pii/ to /abs/pii/ by script after the document has loaded). A site
|
|
317
|
+
without a rule of its own gets the shared one (``page_supplements``); a
|
|
318
|
+
Figshare resource set aside is recorded on ``result``, not returned."""
|
|
317
319
|
for attempt in range(3):
|
|
318
320
|
try:
|
|
319
321
|
from ..adapters.platforms.figshare import supplement_links as external_links
|
|
322
|
+
from .page_supplements import listed_files
|
|
320
323
|
|
|
321
324
|
own = self.adapter.supplement_links(page, doi)
|
|
325
|
+
if own is None:
|
|
326
|
+
own = listed_files(page, doi) or None
|
|
322
327
|
external = external_links(page, doi)
|
|
328
|
+
if result is not None:
|
|
329
|
+
for link in external or ():
|
|
330
|
+
if link.set_aside:
|
|
331
|
+
self._event(result, "supplements_set_aside", f"{link.set_aside} {link.url}")
|
|
332
|
+
external = [link for link in external or () if not link.set_aside] or None
|
|
323
333
|
if own is None and external is None:
|
|
324
334
|
from ..adapters.platforms.silverchair import declares_no_supplements
|
|
325
335
|
|
|
@@ -15,6 +15,7 @@ from __future__ import annotations
|
|
|
15
15
|
import html
|
|
16
16
|
import json
|
|
17
17
|
import re
|
|
18
|
+
import shutil
|
|
18
19
|
import time
|
|
19
20
|
from pathlib import Path
|
|
20
21
|
from typing import Any
|
|
@@ -60,6 +61,17 @@ _FAILURE_KINDS = {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
|
|
64
|
+
def _move_into_place(src: Path, output_path: Path) -> None:
|
|
65
|
+
"""Put a captured PDF at ``output_path``. The backend saves it in its run folder
|
|
66
|
+
first, which is in PaperSearch's own data (since 0.5.13) and can sit on another
|
|
67
|
+
drive than the download folder: a rename cannot cross drives (WinError 17, Windows
|
|
68
|
+
with D:\\Downloads, 2026-11-11), so the file is moved, copied when it must."""
|
|
69
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
if output_path.exists():
|
|
71
|
+
output_path.unlink()
|
|
72
|
+
shutil.move(str(src), str(output_path))
|
|
73
|
+
|
|
74
|
+
|
|
63
75
|
def _remember_blocked_journal(doi: str, identity: dict[str, Any]) -> None:
|
|
64
76
|
"""The journal whose site blocked the current network (``blocked_journals``)."""
|
|
65
77
|
from .. import blocked_journals
|
|
@@ -216,10 +228,7 @@ def _instsci_result_to_dict(result, doi: str, output_path: Path) -> dict[str, An
|
|
|
216
228
|
src = Path(paper.pdf_path)
|
|
217
229
|
if src.exists():
|
|
218
230
|
if src != output_path:
|
|
219
|
-
|
|
220
|
-
if output_path.exists():
|
|
221
|
-
output_path.unlink()
|
|
222
|
-
src.rename(output_path)
|
|
231
|
+
_move_into_place(src, output_path)
|
|
223
232
|
return {
|
|
224
233
|
"success": True, "identifier": doi, "doi": doi,
|
|
225
234
|
"file": str(output_path),
|
|
@@ -457,10 +466,7 @@ def _try_session_broker(
|
|
|
457
466
|
if pdf_path and Path(pdf_path).exists():
|
|
458
467
|
src = Path(pdf_path)
|
|
459
468
|
if src != output_path:
|
|
460
|
-
|
|
461
|
-
if output_path.exists():
|
|
462
|
-
output_path.unlink()
|
|
463
|
-
src.rename(output_path)
|
|
469
|
+
_move_into_place(src, output_path)
|
|
464
470
|
log.info(f" [Institutional] Session broker download succeeded")
|
|
465
471
|
return {
|
|
466
472
|
"success": True, "identifier": doi, "doi": doi,
|
|
@@ -630,10 +636,7 @@ def _try_browser_batch_download(
|
|
|
630
636
|
src = Path(result.pdf_path)
|
|
631
637
|
if src.exists():
|
|
632
638
|
if src != output_path:
|
|
633
|
-
|
|
634
|
-
if output_path.exists():
|
|
635
|
-
output_path.unlink()
|
|
636
|
-
src.rename(output_path)
|
|
639
|
+
_move_into_place(src, output_path)
|
|
637
640
|
result.pdf_path = str(output_path)
|
|
638
641
|
_note_supplements(result, len(getattr(result, "events", [])))
|
|
639
642
|
log.info(f" [Institutional] Browser download succeeded: {result.size_bytes:,} bytes")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""The shared rule for a site without a supplementary-file rule of its own: the
|
|
2
|
+
files the article page itself lists as its supplementary material.
|
|
3
|
+
|
|
4
|
+
A link counts only inside the page's supplementary part (an element whose class
|
|
5
|
+
or id says so, or the part under a "Supplementary data", "Supplemental
|
|
6
|
+
material" or "Supporting information" heading), only when its address names this
|
|
7
|
+
article's DOI ("/" kept, or as "_") between two "/", and only when it ends in a
|
|
8
|
+
file name. The DOI in the address binds the file to this article; a page's links
|
|
9
|
+
to other articles, datasets or web pages are no files of it (the Journal of
|
|
10
|
+
Experimental Medicine's tables on its own CDN, 2026-11-11).
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
from typing import Any
|
|
16
|
+
from urllib.parse import unquote, urlparse
|
|
17
|
+
|
|
18
|
+
from ..adapters.base import SupplementLink
|
|
19
|
+
|
|
20
|
+
_SECTION_LINKS_JS = r"""() => {
|
|
21
|
+
const part = '[class*="suppl" i], [id*="suppl" i], [class*="datasupp" i], [class*="supporting" i], [id*="supporting" i]';
|
|
22
|
+
const heading = /^(?:online )?(?:supplementa(?:ry|l) (?:data|materials?|information|files?)|supporting information)$/i;
|
|
23
|
+
const headed = [...document.querySelectorAll('h1, h2, h3, h4, h5, h6, [role="heading"]')]
|
|
24
|
+
.filter(h => heading.test((h.textContent || '').replace(/\s+/g, ' ').trim()) && h.parentElement)
|
|
25
|
+
.map(h => h.parentElement);
|
|
26
|
+
return {
|
|
27
|
+
doi: document.querySelector('meta[name="citation_doi"]')?.content || '',
|
|
28
|
+
rows: [...document.querySelectorAll('a[href]')]
|
|
29
|
+
.filter(a => a.closest(part) || headed.some(p => p.contains(a)))
|
|
30
|
+
.map(a => ({href: a.href, label: (a.innerText || a.getAttribute('title') || '').replace(/\s+/g, ' ').trim().slice(0, 200)}))
|
|
31
|
+
};
|
|
32
|
+
}"""
|
|
33
|
+
# Addresses that end in a web page, not a file (figure slides are .aspx).
|
|
34
|
+
_WEB_PAGES = frozenset({"html", "htm", "xhtml", "shtml", "asp", "aspx", "php", "jsp", "cfm"})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def listed_files(page: Any, doi: str) -> list[SupplementLink]:
|
|
38
|
+
"""This article's files in its page's supplementary part (see the module); a
|
|
39
|
+
page that names another article in ``citation_doi`` lists none. A file linked
|
|
40
|
+
several times (signed addresses differ in their query) is taken once."""
|
|
41
|
+
doi = (doi or "").strip().lower()
|
|
42
|
+
data = page.evaluate(_SECTION_LINKS_JS)
|
|
43
|
+
if not doi or not isinstance(data, dict):
|
|
44
|
+
return []
|
|
45
|
+
page_doi = str(data.get("doi") or "").strip().lower()
|
|
46
|
+
if page_doi and page_doi != doi:
|
|
47
|
+
return []
|
|
48
|
+
forms = (f"/{doi}/", f"/{doi.replace('/', '_')}/")
|
|
49
|
+
links: list[SupplementLink] = []
|
|
50
|
+
seen: set[tuple[str, str]] = set()
|
|
51
|
+
rows = data.get("rows")
|
|
52
|
+
for row in rows if isinstance(rows, list) else ():
|
|
53
|
+
if not isinstance(row, dict):
|
|
54
|
+
continue
|
|
55
|
+
target = urlparse(str(row.get("href") or ""))
|
|
56
|
+
path = unquote(target.path)
|
|
57
|
+
name = path.rsplit("/", 1)[-1]
|
|
58
|
+
extension = name.rpartition(".")[2].lower() if "." in name else ""
|
|
59
|
+
if (target.scheme != "https" or not target.hostname or target.username or target.password
|
|
60
|
+
or not any(form in path.lower() for form in forms)
|
|
61
|
+
or not re.fullmatch(r"[a-z0-9]{1,5}", extension) or extension in _WEB_PAGES):
|
|
62
|
+
continue
|
|
63
|
+
key = (target.hostname.lower(), path)
|
|
64
|
+
if key not in seen:
|
|
65
|
+
seen.add(key)
|
|
66
|
+
links.append(SupplementLink(target._replace(fragment="").geturl(), str(row.get("label") or "")))
|
|
67
|
+
return links
|
|
@@ -376,8 +376,6 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
376
376
|
"title": str(state.get("title") or ""), "current": current,
|
|
377
377
|
"run_id": str(state.get("run_id") or ""),
|
|
378
378
|
"step": step, "steps": list(STEPS), "line": status_text(state, running) if running else "",
|
|
379
|
-
# What each lane got in a batch checking open access beside its downloads, on one line.
|
|
380
|
-
"lanes": str(state.get("lanes") or "") if running else "",
|
|
381
379
|
"elapsed": elapsed, "attention": prompt, "notice": notice,
|
|
382
380
|
"completion_detail": str(state.get("phase") or "")
|
|
383
381
|
if not running and state.get("stage") == "supplements_checked" else "",
|
|
@@ -18,7 +18,7 @@ export const CARSI_DOWNLOAD_TIMEOUT_MS = 1_200_000;
|
|
|
18
18
|
export const CARSI_CLEANUP_TIMEOUT_MS = 5_000;
|
|
19
19
|
const CARSI_BACKEND_SOURCE = "carsi";
|
|
20
20
|
// MCP clientInfo is informational only; keep in step with package.json on release.
|
|
21
|
-
const PAPER_SEARCH_MCP_CLIENT_VERSION = "0.5.
|
|
21
|
+
const PAPER_SEARCH_MCP_CLIENT_VERSION = "0.5.15";
|
|
22
22
|
const NO_BATCH_SUPPORT = {
|
|
23
23
|
downloadFields: false,
|
|
24
24
|
supplementsField: false,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ description: |
|
|
|
4
4
|
用本机 paper-search 命令做文献工作:检索论文、核对 DOI/PMID、搜正文片段(找方法和结果的原文)、查期刊影响因子与分区、查施引和参考文献、下载全文和补充材料。
|
|
5
5
|
用户要找文献、查期刊、下载论文,或说“请开始配置”时使用;英文请求(literature search、journal metrics、paper download、start setup)同样适用。
|
|
6
6
|
metadata:
|
|
7
|
-
version: "0.5.
|
|
7
|
+
version: "0.5.15"
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
# 文献检索与下载(paper-search)
|
|
@@ -113,7 +113,7 @@ paper-search failures --run <运行ID> --doi <DOI> --export ./failure-report.zip
|
|
|
113
113
|
|
|
114
114
|
- `download_with_fallback` / `download_batch` 的 `content`:`main`(默认,只要正文)、`supplements`(只要补充材料,不走正文的各层)、`both`(正文和补充材料)。
|
|
115
115
|
- 补充材料只经学校订阅下载的浏览器取得:正文由开放渠道拿到时,`both` 会再请它单独取补充材料;它没装或没启用时,这一步记为 `skipped`,写明没有可用的后端。
|
|
116
|
-
- 哪些出版社有补充材料规则见 `publisher-support.md`。完成检查但页面未列出附件时返回空 `supplements`,attempt 为 `skipped/no_supplements`;只取补充材料时整体 `status=ok
|
|
116
|
+
- 哪些出版社有补充材料规则见 `publisher-support.md`。完成检查但页面未列出附件时返回空 `supplements`,attempt 为 `skipped/no_supplements`;只取补充材料时整体 `status=ok`,表示检查完成,不表示保存了文件。这家网站没有补充材料专门规则时先按通用规则取文章页补充材料区块里地址带本文 DOI 的文件,仍没有找到时 attempt 为 `skipped/supplements_not_supported`,整体仍为 `ok`:不知道有没有附件,告诉用户“网站暂不支持自动下载附录”,需要的话打开文章页手动下载,不要说成没有附录。登录未完成(`login_required`)、验证未完成(`challenge_timeout`)、网站的人机验证页挡住了附件下载(`verification_page`,如 Figshare)、拿到网页而不是文件(`html_page`)与其他下载失败分别报告,只取补充材料时为 `error`,不影响已保存正文。
|
|
117
117
|
- 文件存在 `<savePath>/<期刊_年份_标题_短标识>/supplements/`,正文也移进这个文件夹;没取到附件的论文,正文平铺在 `<savePath>` 里;`…_supplements-manifest.json` 记录每个文件的状态(`saved`、`failed`、`skipped`)和原因,在结果 `runLog` 所指的运行记录目录里:有文件没下到时在 `diagnostics/`,都下到时在 `records/`;结果里的 `supplements` 给出实际文件路径。
|
|
118
118
|
- 上限:每篇最多 50 个文件,每个不超过 200 MB,一篇总共 3 分钟;超出的记 `skipped`(原因 `file_limit`、`too_large`、`time_budget`)。`html_page` 表示链接打开的是网页而不是文件,`http_403` 一类是网站拒绝。
|
|
119
119
|
- 只收本文的文件:别的文章的文件、本文的插图、参考文献里的链接都不收。Figshare 公开 article/collection 链接按原文 DOI 关联后解析文件;其他外部附件平台仍需适配。
|
|
@@ -163,7 +163,7 @@ paper-search run download_with_fallback --json-args '{"source":"crossref","paper
|
|
|
163
163
|
|
|
164
164
|
一组论文(几十到几百篇)用一次按顺序执行的 `download_batch`,不要循环调用单篇下载:
|
|
165
165
|
|
|
166
|
-
- `"mode"`:默认 `"two_phase"`,每篇先试开放渠道,没拿到的随即走机构下载(一次一篇),两路同时进行,浏览器和学校登录在开始后几秒就出现;进度窗口按整批计数(k / N),装了学校订阅下载时,5
|
|
166
|
+
- `"mode"`:默认 `"two_phase"`,每篇先试开放渠道,没拿到的随即走机构下载(一次一篇),两路同时进行,浏览器和学校登录在开始后几秒就出现;进度窗口按整批计数(k / N),装了学校订阅下载时,5 篇以上的批量从开头就显示;`"per_item"` 每篇走完整个漏斗;`"entitled_only"` 跳过开放渠道,每篇直接走机构下载(用于测试学校这条路)。
|
|
167
167
|
- 不传 `savePath` 时存到 `DEFAULT_DOWNLOAD_PATH`;整批或每篇都可以带自己的 `savePath`,用户指定了别的文件夹时才传。
|
|
168
168
|
- `"content"`:`"main"`(默认,只要正文)、`"supplements"`(只要本文的补充材料,不走正文的各层)、`"both"`。补充材料存在 `<savePath>/<期刊_年份_标题_短标识>/supplements/`(只下正文时正文直接放在 `<savePath>` 里),清单与浏览器诊断在结果 `runLog` 所指运行记录目录的 `diagnostics/`(都下到时在 `records/`),结果的 `supplements` 列出每个文件的状态;只经机构下载后端获取,哪些出版社有规则见 `publisher-support.md`。
|
|
169
169
|
- 每次下载都会写一份本地运行记录,结果里的 `runLog` 是它的目录(`run.json`;`items.jsonl`,含每一层的耗时、代码,以及后端的页面事件和截图;`timeline.log`)。排查失败时读它,不要猜。结果列出每一篇和它的各次尝试。
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
- 程序按 DOI 实际跳转到的网站判断属于哪一行。DOI 前缀只是线索,期刊换了出版社时前缀不变(例如 ARD 的 `10.1136` 文章现在在 Elsevier)。
|
|
7
7
|
- 用户问“某本期刊能不能下”:先按这张表说明程序能不能走通,再说明学校订阅要以实际下载为准;不要凭这张表断定学校有或没有权限。
|
|
8
8
|
|
|
9
|
-
符号:✓ 实测取得;✓OA 只实测过开放获取文章;○ 已有规则,尚无文件下载成功记录;—
|
|
9
|
+
符号:✓ 实测取得;✓OA 只实测过开放获取文章;○ 已有规则,尚无文件下载成功记录;— 没有补充材料专门规则:按通用规则取文章页补充材料区块里地址带本文 DOI 的文件,取不到时返回 `supplements_not_supported`,正文不受影响。
|
|
10
10
|
|
|
11
11
|
## 有专门规则的出版社
|
|
12
12
|
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
| Frontiers | frontiersin.org | `10.3389` | ✓OA | ✓ |
|
|
49
49
|
| PLOS、Copernicus | 各自网站 | `10.1371`、`10.5194` | ✓ | ✓ |
|
|
50
50
|
|
|
51
|
-
AIP、Optica、Royal Society 的补充材料在 Figshare 上,程序按文章页上的 Figshare 链接取文件。页面没有 Figshare 链接时:AIP 页面标明没有补充材料的,返回空清单;Optica 返回 `supplements_not_supported`,不说明这篇有没有附件。
|
|
51
|
+
AIP、Optica、Royal Society 的补充材料在 Figshare 上,程序按文章页上的 Figshare 链接取文件。页面没有 Figshare 链接时:AIP 页面标明没有补充材料的,返回空清单;Optica 返回 `supplements_not_supported`,不说明这篇有没有附件。Figshare 上的资源既没有标明属于这篇、文章页上的链接也不是“补充材料”字样时(只在数据可用性声明里提到的数据集),不下载,也不算补充材料失败。
|
|
52
52
|
|
|
53
53
|
## 没有专门规则的网站
|
|
54
54
|
|