papersearch 0.8.0 → 0.8.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.
Files changed (101) hide show
  1. package/NOTICE +1 -1
  2. package/README.fr.md +5 -8
  3. package/README.ja.md +5 -8
  4. package/README.ko.md +5 -8
  5. package/README.md +148 -151
  6. package/README.zh-Hant.md +5 -8
  7. package/README.zh.md +265 -0
  8. package/dist/capabilities/download/batch/batch.d.ts +4 -0
  9. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  10. package/dist/capabilities/download/batch/batch.js +714 -198
  11. package/dist/capabilities/download/batch/batch.js.map +1 -1
  12. package/dist/capabilities/download/batch/windowPlan.d.ts +96 -0
  13. package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
  14. package/dist/capabilities/download/batch/windowPlan.js +196 -0
  15. package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
  16. package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
  17. package/dist/capabilities/download/content/markdown/step.js +4 -1
  18. package/dist/capabilities/download/content/markdown/step.js.map +1 -1
  19. package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -1
  20. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
  21. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -1
  22. package/dist/infrastructure/http/hostGate.d.ts +24 -0
  23. package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
  24. package/dist/infrastructure/http/hostGate.js +72 -0
  25. package/dist/infrastructure/http/hostGate.js.map +1 -0
  26. package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
  27. package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
  28. package/dist/infrastructure/pdf/PdfDownload.js +6 -1
  29. package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
  30. package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
  31. package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
  32. package/dist/infrastructure/runlog/RunLedger.js +17 -4
  33. package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
  34. package/dist/infrastructure/school/SchoolMcpClient.d.ts +12 -2
  35. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  36. package/dist/infrastructure/school/SchoolMcpClient.js +122 -11
  37. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  38. package/dist/infrastructure/school/SchoolReadiness.d.ts +7 -0
  39. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  40. package/dist/infrastructure/school/SchoolReadiness.js +8 -0
  41. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  42. package/dist/infrastructure/school/index.d.ts +1 -1
  43. package/dist/infrastructure/school/index.d.ts.map +1 -1
  44. package/dist/infrastructure/school/types.d.ts +31 -1
  45. package/dist/infrastructure/school/types.d.ts.map +1 -1
  46. package/dist/infrastructure/school/types.js.map +1 -1
  47. package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
  48. package/dist/infrastructure/security/SecurityUtils.js +6 -2
  49. package/dist/infrastructure/security/SecurityUtils.js.map +1 -1
  50. package/dist/management/failures/index.d.ts.map +1 -1
  51. package/dist/management/failures/index.js +5 -2
  52. package/dist/management/failures/index.js.map +1 -1
  53. package/dist/management/school/autoUpdate.d.ts.map +1 -1
  54. package/dist/management/school/autoUpdate.js +9 -1
  55. package/dist/management/school/autoUpdate.js.map +1 -1
  56. package/dist/management/school/cliProgress.d.ts.map +1 -1
  57. package/dist/management/school/cliProgress.js +3 -1
  58. package/dist/management/school/cliProgress.js.map +1 -1
  59. package/package.json +2 -2
  60. package/school/paper_search_school/adapters/base.py +3 -0
  61. package/school/paper_search_school/adapters/optica/__init__.py +50 -4
  62. package/school/paper_search_school/adapters/platforms/atypon/__init__.py +4 -3
  63. package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
  64. package/school/paper_search_school/assets/capsule.html +380 -41
  65. package/school/paper_search_school/assets/capsule_en.json +72 -4
  66. package/school/paper_search_school/assets/capsule_fr.json +72 -4
  67. package/school/paper_search_school/assets/capsule_ja.json +72 -4
  68. package/school/paper_search_school/assets/capsule_ko.json +72 -4
  69. package/school/paper_search_school/assets/capsule_zh-Hant.json +66 -3
  70. package/school/paper_search_school/browser/backend.py +125 -4
  71. package/school/paper_search_school/browser/batch_session.py +188 -7
  72. package/school/paper_search_school/browser/challenge/continuation.py +19 -1
  73. package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +38 -10
  74. package/school/paper_search_school/browser/challenge/pro.py +24 -0
  75. package/school/paper_search_school/browser/challenge/services/solver.py +24 -4
  76. package/school/paper_search_school/browser/engine.py +4 -1
  77. package/school/paper_search_school/browser/user_turn.py +126 -0
  78. package/school/paper_search_school/browser/watchdog.py +213 -60
  79. package/school/paper_search_school/config.py +5 -0
  80. package/school/paper_search_school/engine/batch.py +9 -7
  81. package/school/paper_search_school/engine/batch_access.py +27 -7
  82. package/school/paper_search_school/engine/batch_capture.py +45 -13
  83. package/school/paper_search_school/engine/batch_institution.py +14 -0
  84. package/school/paper_search_school/engine/batch_login.py +177 -22
  85. package/school/paper_search_school/engine/batch_user.py +48 -3
  86. package/school/paper_search_school/engine/batch_waits.py +42 -2
  87. package/school/paper_search_school/engine/bridge.py +1 -2
  88. package/school/paper_search_school/engine/fulltext_page.py +10 -1
  89. package/school/paper_search_school/engine/supplements.py +7 -1
  90. package/school/paper_search_school/entitlements.py +28 -0
  91. package/school/paper_search_school/progress_capsule.py +33 -5
  92. package/school/paper_search_school/progress_reporter.py +189 -6
  93. package/school/paper_search_school/progress_view.py +142 -48
  94. package/school/paper_search_school/rate_limit.py +24 -1
  95. package/school/paper_search_school/school_login.py +170 -8
  96. package/school/paper_search_school/server.py +164 -19
  97. package/school/paper_search_school/user_settings.py +33 -4
  98. package/skills/paper-search/SKILL.md +1 -1
  99. package/skills/paper-search/references/browser-download.md +2 -2
  100. package/LICENSE-paper-search-mcp-nodejs +0 -24
  101. package/README.en.md +0 -268
@@ -6,6 +6,7 @@ from dataclasses import dataclass
6
6
  from typing import Any
7
7
 
8
8
  from .services import solver
9
+ from . import pro
9
10
 
10
11
 
11
12
  class Expired(Exception):
@@ -41,7 +42,9 @@ def resume(page: Any, config: dict, *, kind: str, limits: Limits, observation: A
41
42
  IdP boundary before local actions and before every service continuation.
42
43
  """
43
44
  note = observation
44
- if kind not in {"awswaf", "recaptcha", "hcaptcha", "image_code", "turnstile"}:
45
+ extension = pro.verification()
46
+ handler = extension.HANDLERS.get(kind) if extension is not None else None
47
+ if not callable(handler) and kind not in {"awswaf", "recaptcha", "hcaptcha", "image_code", "turnstile"}:
45
48
  note(f"service unsupported: {kind}; no handler")
46
49
  return False
47
50
  if not solver.configured(config):
@@ -49,6 +52,21 @@ def resume(page: Any, config: dict, *, kind: str, limits: Limits, observation: A
49
52
  return False
50
53
  try:
51
54
  limits.remaining()
55
+ if callable(handler):
56
+ try:
57
+ result = handler(page, config, kind=kind, limits=limits, observation=note)
58
+ if not isinstance(result, bool):
59
+ raise TypeError('invalid Pro handler result')
60
+ return result
61
+ except Expired:
62
+ raise
63
+ except Exception as exc:
64
+ limits.remaining() # Cancellation and expiry remain authoritative.
65
+ pro.log.warning("PaperSearch Pro verification handler failed (%s); using public handler",
66
+ type(exc).__name__)
67
+ if kind not in {"awswaf", "recaptcha", "hcaptcha", "image_code", "turnstile"}:
68
+ note(f"service unsupported: {kind}; no public fallback")
69
+ return False
52
70
  if kind == "turnstile":
53
71
  from .handlers import turnstile
54
72
  return turnstile.solve(page, config, limits=limits, observation=note)
@@ -3,6 +3,8 @@
3
3
  Geometry and form structure, not publisher domains, identify the code. Visible
4
4
  password/email fields and article metadata exclude login/article pages. No
5
5
  hidden fields, cookies, DOM text answers or full-page images leave the browser.
6
+ Without Pro the 0.8.0 displayed-image, single-reading behavior is preserved.
7
+ Pro can provide its own reader through the optional versioned interface.
6
8
  """
7
9
  from __future__ import annotations
8
10
 
@@ -10,6 +12,8 @@ from typing import Any
10
12
 
11
13
  from ...driver import Error
12
14
  from ..services import solver
15
+ from .. import pro
16
+ from ..continuation import Expired
13
17
  from ..local import submission
14
18
 
15
19
  _FIND = r'''() => {
@@ -67,18 +71,42 @@ def solve(page: Any, config: dict, *, limits: Any, observation: Any) -> bool:
67
71
  if not controls:
68
72
  note('image_code: no unambiguous standalone code form')
69
73
  return False
70
- picture = page.locator(controls['picture'])
71
- image = picture.screenshot(scale='css', timeout=min(2000, int(limits.remaining()*1000)))
72
- if not limits.budget.take():
73
- note('service budget exhausted')
74
- return False
75
- answer = solver.solve_image(image, config, timeout=min(limits.remaining(), float(config.get('captcha_timeout', 90))),
76
- checkpoint=limits.remaining)
74
+ spent = []
75
+
76
+ def ask(image, **options):
77
+ # The host owns transport and the shared request budget, not reading rules.
78
+ if not limits.budget.take():
79
+ spent.append(True)
80
+ return None
81
+ return solver.solve_image(image, config, timeout=min(limits.remaining(), float(config.get('captcha_timeout', 90))),
82
+ checkpoint=limits.remaining, **options)
83
+
84
+ extension = pro.verification()
85
+ image = None
86
+ if extension is not None:
87
+ try:
88
+ answer = extension.read_code(page, controls['picture'], controls['field'], ask)
89
+ if not isinstance(answer, str):
90
+ raise TypeError('invalid Pro reader result')
91
+ except Expired:
92
+ raise
93
+ except Exception as exc:
94
+ limits.remaining()
95
+ pro.log.warning('PaperSearch Pro code reader failed (%s); using public reader', type(exc).__name__)
96
+ extension = None
97
+ if extension is None:
98
+ # Published 0.8.0 behavior, including screenshot scale and strict text acceptance.
99
+ picture = page.locator(controls['picture'])
100
+ image = picture.screenshot(scale='css', timeout=min(2000, int(limits.remaining()*1000)))
101
+ answer = ask(image)
102
+ if answer and (len(answer) > 64 or not answer.isalnum()):
103
+ answer = None
77
104
  limits.remaining()
78
- if not answer or len(answer)>64 or not answer.isalnum():
79
- note('image_code: service failed or invalid text')
105
+ if not answer:
106
+ note('service budget exhausted' if spent else 'image_code: service failed or invalid text')
80
107
  return False
81
- if controls != find(page) or image != picture.screenshot(scale='css', timeout=min(2000, int(limits.remaining()*1000))):
108
+ if (controls != find(page) or (image is not None and image != picture.screenshot(
109
+ scale='css', timeout=min(2000, int(limits.remaining()*1000))))):
82
110
  note('image_code: code changed; discard answer')
83
111
  continue
84
112
  page.locator(controls['field']).fill(answer, timeout=min(2000, int(limits.remaining()*1000)))
@@ -0,0 +1,24 @@
1
+ """Versioned optional Pro strategies, loaded through the existing Pro access boundary."""
2
+ import logging
3
+ from ... import school_login
4
+
5
+ log = logging.getLogger(__name__)
6
+ API = 1
7
+
8
+
9
+ def verification():
10
+ """None preserves the public behavior when Pro is absent or incompatible."""
11
+ try:
12
+ module = school_login.module()
13
+ extension = getattr(module, "verification_api", None)
14
+ if extension is None:
15
+ return None
16
+ if (getattr(extension, "API", None) != API
17
+ or not callable(getattr(extension, "read_code", None))
18
+ or not isinstance(getattr(extension, "HANDLERS", None), dict)):
19
+ log.warning("PaperSearch Pro verification interface is incompatible; using public handlers")
20
+ return None
21
+ return extension
22
+ except Exception as exc:
23
+ log.warning("PaperSearch Pro verification did not load (%s); using public handlers", type(exc).__name__)
24
+ return None
@@ -20,6 +20,11 @@ DEFAULT_MAX_PER_RUN = 20
20
20
  KEY_FILE = Path.home() / ".config" / "paper-search-cli" / "yescaptcha.key"
21
21
  SOFT_ID = 149362
22
22
  IMAGE_TASK = "ImageToTextTaskOcrBase"
23
+ #: The image task that takes requirements (``math``: a sum's result answered; ``numeric``: 1 digits only, 2 no digits;
24
+ #: ``maxLength``), asynchronous and 4 points against 2 (docs.yescaptcha.com/zh/tasks/image-to-text, 2026-11-26).
25
+ #: Used for school sign-in codes whose page states them.
26
+ OPTIONS_TASK = "ImageToTextTask"
27
+ M1_TASK = "ImageToTextTaskM1"
23
28
  GRID_TASK = "AwsClassification"
24
29
  TASKS = {
25
30
  "image_code": IMAGE_TASK,
@@ -111,12 +116,27 @@ def get_balance(config: dict[str, Any] | None, *, post: Callable[..., Any] | Non
111
116
 
112
117
  def solve_image(image: bytes, config: dict[str, Any] | None, *,
113
118
  post: Callable[..., Any] | None = None,
114
- timeout: float | None = None, checkpoint: Any = None) -> str | None:
115
- """Return recognized characters, or None on failure."""
119
+ timeout: float | None = None, checkpoint: Any = None,
120
+ math: bool = False, numeric: int = 0, max_length: int = 0, m1: bool = False) -> str | None:
121
+ """Return recognized characters, or None on failure. ``math``: the picture is a sum, its result returned;
122
+ ``numeric`` (1 digits only, 2 no digits) and ``max_length``: what the answer may be. Any of them asks
123
+ OPTIONS_TASK; none, the plain IMAGE_TASK as before. ``m1`` opts into M1 with case preserved,
124
+ including requirements."""
116
125
  if not image:
117
126
  return None
118
- solution = _solve_task({"type": IMAGE_TASK, "body": base64.b64encode(image).decode("ascii")},
119
- config, timeout=timeout, post=post, checkpoint=checkpoint)
127
+ body = base64.b64encode(image).decode("ascii")
128
+ task: dict[str, Any] = {"type": IMAGE_TASK, "body": body}
129
+ if m1 or math or numeric or max_length:
130
+ task = {"type": M1_TASK if m1 else OPTIONS_TASK, "body": body}
131
+ if m1:
132
+ task["case"] = True
133
+ if math:
134
+ task["math"] = True
135
+ if numeric in (1, 2):
136
+ task["numeric"] = numeric
137
+ if max_length > 0:
138
+ task["maxLength"] = int(max_length)
139
+ solution = _solve_task(task, config, timeout=timeout, post=post, checkpoint=checkpoint)
120
140
  if not solution or not isinstance(solution.get("text"), str):
121
141
  return None
122
142
  return solution["text"].strip() or None
@@ -162,7 +162,10 @@ _atexit.register(_reap_browsers_at_exit)
162
162
 
163
163
  def _build_browser_args(config: dict[str, Any] | None = None) -> list[str]:
164
164
  """Build Chromium launch args from config (proxy, flags, etc.)."""
165
- args = ["--disable-features=CrossOriginOpenerPolicy"]
165
+ # HttpsFirstBalancedModeAutoEnable (user, 2026-11-28): Chrome 158 turns HTTPS-First's balanced mode on by
166
+ # itself, and in a browser a program drives a school's login page on plain http (two schools' login pages: no
167
+ # https there) is tried on https, blocked with ERR_BLOCKED_BY_CLIENT, and never opened on http.
168
+ args = ["--disable-features=CrossOriginOpenerPolicy,HttpsFirstBalancedModeAutoEnable"]
166
169
  if config:
167
170
  proxy = config.get("browser_static_proxy", "")
168
171
  if proxy:
@@ -0,0 +1,126 @@
1
+ """One window at a time asks for the user (并行下载, user 2026-11-29).
2
+
3
+ A batch downloading several papers at once runs each in a window of its own in the one download browser
4
+ (``batch_session.BatchBrowser``). The school's login and a verification the user has to complete come up in one of
5
+ them only: a window that needs the user while another one does waits for its turn, its page answering meanwhile, and
6
+ the other windows go on with their papers. Its time to wait for the user starts when its turn comes, not before.
7
+
8
+ Turns are taken only in a batch whose windows run at once (``start``); a paper on its own, or a batch one paper after
9
+ another, takes none and waits for nobody.
10
+
11
+ A turn is the window's from the step that may ask the user (the school's login, a verification handed to the user)
12
+ to that step's end, nested steps counted (``acquire``/``release``), and never past its paper (``release_all``). A turn
13
+ whose wait on the user ran out unanswered says so (``note_expired``): a window whose turn came after it was waiting
14
+ for an absent user too, and waits for the user only briefly (the batch's ``user_wait`` "short").
15
+ """
16
+ from __future__ import annotations
17
+
18
+ import threading
19
+ import time
20
+ from contextvars import ContextVar
21
+ from typing import Callable
22
+
23
+ _cond = threading.Condition()
24
+ _holder: int | None = None
25
+ _depth = 0
26
+ _parallel = False
27
+ _expired_at = 0.0
28
+ _window: ContextVar[int | None] = ContextVar("papersearch_batch_window", default=None)
29
+ #: How often a window waiting for its turn lets its page answer (its pump).
30
+ POLL_SEC = 0.25
31
+
32
+
33
+ def start(parallel: bool) -> None:
34
+ """A batch begins (server.py): its windows take turns when it runs several at once."""
35
+ global _parallel, _holder, _depth
36
+ with _cond:
37
+ _parallel = bool(parallel)
38
+ _holder, _depth = None, 0
39
+ _cond.notify_all()
40
+
41
+
42
+ def bind(window: int | None):
43
+ """The window the current download runs in (server.py, on the window's own thread); returns the token to reset."""
44
+ return _window.set(window)
45
+
46
+
47
+ def unbind(token) -> None:
48
+ _window.reset(token)
49
+
50
+
51
+ def window() -> int | None:
52
+ """The window of the current download in a batch whose windows run at once; None otherwise."""
53
+ found = _window.get()
54
+ return found if _parallel and found is not None else None
55
+
56
+
57
+ def active() -> bool:
58
+ """Whether the current download takes turns with other windows."""
59
+ return window() is not None
60
+
61
+
62
+ def acquire(pump: Callable[[], None] | None = None) -> float:
63
+ """The current window's turn to ask for the user: at once when no other window has it (or this one already
64
+ does, a step within a step), else once the other's ends, ``pump`` called meanwhile (its page answering, the
65
+ user's buttons read). Returns the seconds waited."""
66
+ global _holder, _depth
67
+ me = window()
68
+ if me is None:
69
+ return 0.0
70
+ started = time.monotonic()
71
+ while True:
72
+ with _cond:
73
+ if _holder is None or _holder == me:
74
+ _holder = me
75
+ _depth += 1
76
+ return time.monotonic() - started
77
+ if pump is None:
78
+ _cond.wait(POLL_SEC)
79
+ continue
80
+ pump()
81
+
82
+
83
+ def release() -> None:
84
+ """The current window's step that asked for the user ended: its turn ends with its outermost one."""
85
+ global _holder, _depth
86
+ me = window()
87
+ if me is None:
88
+ return
89
+ with _cond:
90
+ if _holder != me:
91
+ return
92
+ _depth -= 1
93
+ if _depth <= 0:
94
+ _holder, _depth = None, 0
95
+ _cond.notify_all()
96
+
97
+
98
+ def release_all() -> None:
99
+ """The current window's paper ended: whatever turn it held ends with it."""
100
+ global _holder, _depth
101
+ me = window()
102
+ if me is None:
103
+ return
104
+ with _cond:
105
+ if _holder == me:
106
+ _holder, _depth = None, 0
107
+ _cond.notify_all()
108
+
109
+
110
+ def holder() -> int | None:
111
+ """The window whose turn it is, or None."""
112
+ with _cond:
113
+ return _holder
114
+
115
+
116
+ def note_expired() -> None:
117
+ """A wait on the user ran out unanswered: the user seems away."""
118
+ global _expired_at
119
+ with _cond:
120
+ _expired_at = time.monotonic()
121
+
122
+
123
+ def expired_since(since: float) -> bool:
124
+ """Whether a wait on the user ran out after ``since`` (time.monotonic())."""
125
+ with _cond:
126
+ return _expired_at > since