papersearch 0.7.2 → 0.8.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.
Files changed (177) hide show
  1. package/LICENSE-paper-search-mcp-nodejs +24 -0
  2. package/NOTICE +8 -37
  3. package/README.en.md +7 -3
  4. package/README.fr.md +268 -0
  5. package/README.ja.md +268 -0
  6. package/README.ko.md +268 -0
  7. package/README.md +7 -3
  8. package/README.zh-Hant.md +268 -0
  9. package/dist/capabilities/download/batch/batch.d.ts +16 -1
  10. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  11. package/dist/capabilities/download/batch/batch.js +669 -53
  12. package/dist/capabilities/download/batch/batch.js.map +1 -1
  13. package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
  14. package/dist/capabilities/download/batch/batchFolder.js +4 -3
  15. package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
  16. package/dist/capabilities/download/batch/batchSummary.js +1 -1
  17. package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
  18. package/dist/capabilities/download/batch/networkLoss.d.ts +12 -3
  19. package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
  20. package/dist/capabilities/download/batch/networkLoss.js +25 -4
  21. package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
  22. package/dist/capabilities/download/batch/resume.d.ts +7 -0
  23. package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
  24. package/dist/capabilities/download/batch/resume.js +50 -9
  25. package/dist/capabilities/download/batch/resume.js.map +1 -1
  26. package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
  27. package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
  28. package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
  29. package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
  30. package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
  31. package/dist/capabilities/download/content/markdown/shortfall.js +27 -15
  32. package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
  33. package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
  34. package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
  35. package/dist/capabilities/download/content/markdown/step.js +42 -2
  36. package/dist/capabilities/download/content/markdown/step.js.map +1 -1
  37. package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
  38. package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
  39. package/dist/capabilities/download/handler.d.ts.map +1 -1
  40. package/dist/capabilities/download/handler.js +13 -5
  41. package/dist/capabilities/download/handler.js.map +1 -1
  42. package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
  43. package/dist/capabilities/download/outputLayout.js +3 -1
  44. package/dist/capabilities/download/outputLayout.js.map +1 -1
  45. package/dist/capabilities/download/tools.js +2 -2
  46. package/dist/capabilities/download/tools.js.map +1 -1
  47. package/dist/capabilities/download/types.d.ts +9 -1
  48. package/dist/capabilities/download/types.d.ts.map +1 -1
  49. package/dist/cli.js +3 -1
  50. package/dist/cli.js.map +1 -1
  51. package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
  52. package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
  53. package/dist/infrastructure/runlog/RunLedger.js +13 -0
  54. package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
  55. package/dist/infrastructure/runlog/failureClass.d.ts +17 -9
  56. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  57. package/dist/infrastructure/runlog/failureClass.js +89 -56
  58. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  59. package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
  60. package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
  61. package/dist/infrastructure/school/SchoolAttempt.js +107 -59
  62. package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
  63. package/dist/infrastructure/school/SchoolMcpClient.d.ts +7 -2
  64. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  65. package/dist/infrastructure/school/SchoolMcpClient.js +30 -7
  66. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  67. package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
  68. package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
  69. package/dist/infrastructure/school/SchoolProgress.js +2 -0
  70. package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
  71. package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
  72. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  73. package/dist/infrastructure/school/SchoolReadiness.js +2 -0
  74. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  75. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  76. package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
  77. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  78. package/dist/infrastructure/school/index.d.ts +2 -2
  79. package/dist/infrastructure/school/index.d.ts.map +1 -1
  80. package/dist/infrastructure/school/index.js +1 -1
  81. package/dist/infrastructure/school/index.js.map +1 -1
  82. package/dist/infrastructure/school/types.d.ts +52 -3
  83. package/dist/infrastructure/school/types.d.ts.map +1 -1
  84. package/dist/infrastructure/school/types.js.map +1 -1
  85. package/dist/management/failures/index.d.ts +28 -2
  86. package/dist/management/failures/index.d.ts.map +1 -1
  87. package/dist/management/failures/index.js +83 -21
  88. package/dist/management/failures/index.js.map +1 -1
  89. package/package.json +7 -2
  90. package/school/NOTICE +3 -2
  91. package/school/paper_search_school/adapters/__init__.py +2 -0
  92. package/school/paper_search_school/adapters/aps/__init__.py +3 -6
  93. package/school/paper_search_school/adapters/base.py +18 -0
  94. package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
  95. package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
  96. package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
  97. package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
  98. package/school/paper_search_school/adapters/iop/__init__.py +8 -0
  99. package/school/paper_search_school/adapters/jama/__init__.py +8 -0
  100. package/school/paper_search_school/adapters/lww/__init__.py +14 -6
  101. package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
  102. package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
  103. package/school/paper_search_school/adapters/optica/__init__.py +2 -9
  104. package/school/paper_search_school/adapters/oup/__init__.py +27 -4
  105. package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
  106. package/school/paper_search_school/adapters/platforms/atypon/__init__.py +8 -0
  107. package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
  108. package/school/paper_search_school/adapters/sage/__init__.py +4 -1
  109. package/school/paper_search_school/adapters/thieme/__init__.py +6 -11
  110. package/school/paper_search_school/api_keys.py +63 -13
  111. package/school/paper_search_school/assets/api_keys.json +14 -0
  112. package/school/paper_search_school/assets/capsule.html +274 -158
  113. package/school/paper_search_school/assets/capsule_en.json +99 -98
  114. package/school/paper_search_school/assets/capsule_fr.json +100 -99
  115. package/school/paper_search_school/assets/capsule_ja.json +99 -98
  116. package/school/paper_search_school/assets/capsule_ko.json +99 -98
  117. package/school/paper_search_school/assets/capsule_zh-Hant.json +94 -97
  118. package/school/paper_search_school/browser/batch_session.py +1 -1
  119. package/school/paper_search_school/browser/challenge/__init__.py +12 -9
  120. package/school/paper_search_school/browser/challenge/continuation.py +65 -0
  121. package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
  122. package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
  123. package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
  124. package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +100 -0
  125. package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
  126. package/school/paper_search_school/browser/challenge/kinds.py +203 -0
  127. package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
  128. package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
  129. package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
  130. package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
  131. package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
  132. package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
  133. package/school/paper_search_school/browser/challenge/services/solver.py +272 -0
  134. package/school/paper_search_school/cli_config.py +10 -5
  135. package/school/paper_search_school/cold_start.py +22 -11
  136. package/school/paper_search_school/config.py +11 -10
  137. package/school/paper_search_school/download_diagnostics.py +7 -2
  138. package/school/paper_search_school/engine/access_rules.py +15 -5
  139. package/school/paper_search_school/engine/batch.py +55 -15
  140. package/school/paper_search_school/engine/batch_access.py +59 -21
  141. package/school/paper_search_school/engine/batch_capture.py +215 -18
  142. package/school/paper_search_school/engine/batch_common.py +3 -0
  143. package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
  144. package/school/paper_search_school/engine/batch_institution.py +168 -32
  145. package/school/paper_search_school/engine/batch_login.py +223 -16
  146. package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
  147. package/school/paper_search_school/engine/batch_waits.py +179 -12
  148. package/school/paper_search_school/engine/bridge.py +44 -7
  149. package/school/paper_search_school/engine/fulltext_page.py +45 -7
  150. package/school/paper_search_school/engine/router.py +18 -2
  151. package/school/paper_search_school/entitlements.py +1 -1
  152. package/school/paper_search_school/orchestrator.py +44 -18
  153. package/school/paper_search_school/pdf_utils.py +25 -16
  154. package/school/paper_search_school/progress_capsule.py +36 -6
  155. package/school/paper_search_school/progress_reporter.py +71 -13
  156. package/school/paper_search_school/progress_view.py +64 -44
  157. package/school/paper_search_school/publishers/builtin/iop.json +2 -1
  158. package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
  159. package/school/paper_search_school/publishers/builtin/sage.json +4 -2
  160. package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
  161. package/school/paper_search_school/publishers/site.py +12 -4
  162. package/school/paper_search_school/school_switch.py +34 -52
  163. package/school/paper_search_school/school_test.py +1 -1
  164. package/school/paper_search_school/server.py +24 -11
  165. package/school/paper_search_school/user_settings.py +13 -0
  166. package/school/pyproject.toml +1 -0
  167. package/skills/paper-search/SKILL.md +107 -107
  168. package/skills/paper-search/references/browser-download.md +102 -101
  169. package/skills/paper-search/references/capability-routing.md +89 -89
  170. package/skills/paper-search/references/cli-contract.md +78 -78
  171. package/skills/paper-search/references/federation-support.md +172 -172
  172. package/skills/paper-search/references/management-layer.md +78 -78
  173. package/skills/paper-search/references/publisher-support.md +38 -38
  174. package/skills/paper-search/references/school-setup.md +56 -55
  175. package/skills/paper-search/references/setup.md +20 -20
  176. package/skills/paper-search/references/troubleshooting.md +12 -12
  177. package/school/paper_search_school/browser/challenge/prompt.py +0 -154
@@ -98,9 +98,11 @@ class InstitutionMixin:
98
98
  here = str(getattr(page, "url", "") or "")
99
99
  if self._school_choices_here(result, here) >= self.SCHOOL_CHOICE_REPEATS:
100
100
  return self._after_repeated_school_choice(page, result, here)
101
- # The OpenAthens wayfinder goes straight to the school's entity on the
102
- # route that signs in there.
103
- if federation.openathens_entries and self._select_openathens_wayfinder(page, result):
101
+ # The OpenAthens wayfinder goes straight to the school's entity, also for a federation's school the
102
+ # publisher sends there (LWW's Ovid, Windows 2026-11-22): its search took 40 s, and a school the wayfinder
103
+ # remembered ("Access through <another school>") left the login waiting a minute. The entityID was what
104
+ # its search came to anyway, its CARSI sign-in beside its library's OpenAthens account.
105
+ if self._select_openathens_wayfinder(page, result):
104
106
  return True
105
107
  # Everything except human verification and the user's credentials is
106
108
  # automated once an institution is configured: a remembered
@@ -299,8 +301,18 @@ class InstitutionMixin:
299
301
  return select, hits[0][0], hits[0][1]
300
302
  return None
301
303
 
302
- @staticmethod
303
- def _filled_lists(lists: Any, federation: dict) -> dict:
304
+ # A list of societies to sign in through ("Select your society"; BMJ's #society-login-select, Windows 2026-11-22):
305
+ # not a list of schools, whatever its names ("... College of Sport and Exercise Physicians") or values (addresses).
306
+ _SOCIETY_LIST = re.compile(r"societ", re.I)
307
+
308
+ @classmethod
309
+ def _society_list(cls, select: dict) -> bool:
310
+ options = [o for o in select.get("options") or () if isinstance(o, (list, tuple)) and len(o) == 2]
311
+ return bool(cls._SOCIETY_LIST.search(str(select.get("name") or ""))
312
+ or (options and cls._SOCIETY_LIST.search(str(options[0][1]))))
313
+
314
+ @classmethod
315
+ def _filled_lists(cls, lists: Any, federation: dict) -> dict:
304
316
  """Filled school lists, not the header's journal/language/search lists.
305
317
 
306
318
  Only positive institution evidence can establish that a school is
@@ -309,7 +321,7 @@ class InstitutionMixin:
309
321
  """
310
322
  school = re.compile(r"institut|school|universit|\buniv\b|college|organi[sz]ation|\bidp\b|大学|学院|研究院", re.I)
311
323
  return {str(s.get("name")): list(s.get("options") or ()) for s in lists or ()
312
- if s.get("i") != federation.get("i") and len(s.get("options") or ()) > 1
324
+ if s.get("i") != federation.get("i") and len(s.get("options") or ()) > 1 and not cls._society_list(s)
313
325
  and (school.search(str(s.get("name") or "")) or any(
314
326
  school.search(str(o[1])) for o in s.get("options") or ()
315
327
  if isinstance(o, (list, tuple)) and len(o) == 2))}
@@ -446,8 +458,9 @@ class InstitutionMixin:
446
458
 
447
459
  def _entity_lists(self, lists: Any) -> dict:
448
460
  return {str(s.get("name")): list(s.get("options") or ()) for s in lists or ()
449
- if sum(1 for o in s.get("options") or () if isinstance(o, (list, tuple)) and len(o) == 2
450
- and self._ENTITY_VALUE.match(str(o[0]))) >= self.ENTITY_LIST_MIN}
461
+ if not self._society_list(s)
462
+ and sum(1 for o in s.get("options") or () if isinstance(o, (list, tuple)) and len(o) == 2
463
+ and self._ENTITY_VALUE.match(str(o[0]))) >= self.ENTITY_LIST_MIN}
451
464
 
452
465
  def _check_entity_list(self, page: Any, result: DownloadResult, lists: list[dict], url: str) -> None:
453
466
  """A filled list of schools by entityID without the configured school, the same a
@@ -637,16 +650,17 @@ class InstitutionMixin:
637
650
 
638
651
  _ENTRY_SELECTOR = "li, a, button, [role=option], [role=button]"
639
652
 
640
- # An entry's own identifiers: its link and data attributes, and the hidden
641
- # fields and data attributes of the elements around it that hold no other
642
- # entry (Elsevier keeps each result's entityID in a hidden field, 2026-10-31).
653
+ # An entry's own identifiers: its link, its onclick (JAMA's search entries name their entityID
654
+ # only there, 2026-11-17) and data attributes, and the hidden fields and data attributes of the
655
+ # elements around it that hold no other entry (Elsevier keeps each result's entityID in a hidden
656
+ # field, 2026-10-31).
643
657
  _ENTRIES_JS = """(sel) => {
644
658
  const all = [...document.querySelectorAll(sel)];
645
659
  const visible = el => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
646
660
  const cands = all.filter(visible);
647
661
  const inner = cands.filter(el => !cands.some(o => o !== el && el.contains(o)));
648
662
  const ids = el => {
649
- const out = [el.href || el.getAttribute('href') || ''];
663
+ const out = [el.href || el.getAttribute('href') || '', el.getAttribute('onclick') || ''];
650
664
  for (let row = el, up = 0; row && up < 4; up++) {
651
665
  for (const a of row.attributes || []) if (a.name.startsWith('data-')) out.push(a.value);
652
666
  for (const h of row.querySelectorAll('input[type=hidden]')) out.push(h.value || '');
@@ -661,10 +675,47 @@ class InstitutionMixin:
661
675
  .filter(it => it.t && it.t.length <= 160);
662
676
  }"""
663
677
 
678
+ def _users_own_search(self, page: Any) -> bool:
679
+ """A shown institution search box holding text the program did not type: the user is choosing."""
680
+ queries = {" ".join(q.split()).lower() for q in self._search_queries(list(self._institution_names()))}
681
+ for selector in self._INSTITUTION_INPUTS: # the institution boxes only, the page not read for them
682
+ try:
683
+ boxes = page.locator(selector).all()
684
+ if not isinstance(boxes, list):
685
+ continue
686
+ for box in boxes[:4]:
687
+ if box.is_visible(timeout=300) is not True:
688
+ continue
689
+ value = " ".join(str(box.input_value(timeout=800) or "").split()).lower()
690
+ if value and value not in queries:
691
+ return True
692
+ except Exception as exc:
693
+ if not _is_browser_error(exc):
694
+ raise
695
+ return False
696
+
664
697
  def _institution_entry_score(self, entry: dict, entity_id: str) -> int:
665
- if self._carries_entity_id(str(entry.get("ids") or ""), entity_id):
698
+ ids = str(entry.get("ids") or "")
699
+ if self._carries_entity_id(ids, entity_id):
666
700
  return 4
667
- return self._institution_match_score(entry.get("t", ""))
701
+ score = self._institution_match_score(entry.get("t", ""))
702
+ if score >= 2 and self._names_another_sign_in(ids, entity_id):
703
+ return 1 # the school's name, another sign-in than the saved one: not clicked
704
+ return score
705
+
706
+ # The sign-in an entry names: Atypon's /action/ssostart?idp=<entityID>, SeamlessAccess's
707
+ # saveInstitution(this, '<entityID>') in its onclick (JAMA's search, 2026-11-17).
708
+ _ENTRY_IDP = re.compile(r"[?&]idp=([^&#\s\"']+)|saveInstitution\(\s*[^,()]*,\s*['\"]([^'\"]+)['\"]", re.I)
709
+
710
+ def _names_another_sign_in(self, text: str, entity_id: str) -> bool:
711
+ """An entry's link names an identity provider, and not the school's saved one (Sage listed a test school with
712
+ idp=<its library's OpenAthens entityID>, which sent the login straight back to the article, while its saved
713
+ Shibboleth entityID signs in elsewhere; Windows 2026-11-22)."""
714
+ if not entity_id or not text:
715
+ return False
716
+ named = {unquote(unquote(link or saved)).strip().lower() for link, saved in self._ENTRY_IDP.findall(text)}
717
+ named = {value for value in named if value.startswith(("https://", "http://", "urn:"))}
718
+ return bool(named) and entity_id.strip().lower() not in named
668
719
 
669
720
  def _name_residue(self, text: str) -> str | None:
670
721
  """What is left of ``text`` (lower case) once the school's names are taken
@@ -778,6 +829,11 @@ class InstitutionMixin:
778
829
  recorded, url = unquote(str(recorded or "")), unquote(str(url or ""))
779
830
  return len(recorded) > 10 and url.startswith(recorded)
780
831
 
832
+ def _searched_here(self, result: DownloadResult, url: str) -> bool:
833
+ """The school's name was typed into a search on the page at ``url``."""
834
+ return any(e.get("state") == "auto_institution_search"
835
+ and self._same_address(str(e.get("detail", "")).split(" @ ", 1)[-1], url) for e in result.events)
836
+
781
837
  def _search_queries(self, names: list[str]) -> list[str]:
782
838
  """The school's names to search by (straight apostrophes): its English name
783
839
  first, then the others in Latin letters, its shared login entry's own name
@@ -835,13 +891,15 @@ class InstitutionMixin:
835
891
  and self._same_address(str(e.get("detail", "")).partition(" @ ")[2], url) for e in result.events)
836
892
  if (not settled and not chosen and not getattr(result, "_institution_not_listed", False)
837
893
  and time.time() - float(getattr(result, "_search_typed_at", 0) or 0) >= self.SEARCH_NOTHING_SEC
838
- and (self._search_list_closed(page, result, url) or not self._entry_texts(page) - before)):
894
+ and (self._search_list_closed(page, result, url) or self._search_list_empty(page, result, url)
895
+ or not self._entry_texts(page) - before)):
839
896
  if self._retype_lost_search(page, result, url, tried[-1]):
840
897
  return True
841
898
  result._institution_not_listed = True
842
899
  self._event(result, "institution_search_found_nothing", f"{', '.join(tried)[:120]} @ {url[:200]}")
843
900
  return False
844
- if not settled and not self._search_list_closed(page, result, url) and self._entry_texts(page) - before:
901
+ if (not settled and not self._search_list_closed(page, result, url) and not self._search_list_empty(page, result, url)
902
+ and self._entry_texts(page) - before):
845
903
  return False # results shown: they decide
846
904
  box = page.locator(box_at[1]).first
847
905
  try:
@@ -923,6 +981,29 @@ class InstitutionMixin:
923
981
  raise
924
982
  return True # not readable now: nothing concluded from it
925
983
 
984
+ def _search_list_empty(self, page: Any, result: DownloadResult, url: str) -> bool:
985
+ """The search box typed in names its own list of suggestions (``aria-controls`` or ``aria-owns``, as a combobox
986
+ does) and that list shows none: no results, whatever else appeared on the page meanwhile. Sage's institution
987
+ search (Windows 2026-11-24): its list open and empty, the school not listed; the page's other controls drawn
988
+ after the name was typed (its first visit, past a verification) were taken for results and the login waited
989
+ its whole page wait, 原因不明; the next visit said 没权限 in 10 s. False when the box names no list."""
990
+ box = getattr(result, "_search_box", None)
991
+ if not isinstance(box, tuple) or not self._same_address(box[0], url):
992
+ return False
993
+ try:
994
+ return page.evaluate("""(selector) => {
995
+ const el = document.querySelector(selector);
996
+ const id = el && (el.getAttribute('aria-controls') || el.getAttribute('aria-owns'));
997
+ const list = id && document.getElementById(id.trim().split(' ')[0]);
998
+ if (!list) return false;
999
+ const shown = (o) => o.getClientRects().length > 0 && (o.textContent || '').trim();
1000
+ return ![...list.querySelectorAll('[role=option], li, a, button')].some(shown) && !(list.textContent || '').trim();
1001
+ }""", box[1]) is True
1002
+ except Exception as exc:
1003
+ if not _is_browser_error(exc):
1004
+ raise
1005
+ return False
1006
+
926
1007
  # The site's own line naming the institution it serves the reader for ("brought to
927
1008
  # you by <school>" in Science's header, 2026-11-15) is no entry of a list.
928
1009
  _SESSION_BANNER = re.compile(r"\s*(?:brought to you by|access (?:provided|funded) by)", re.I)
@@ -965,11 +1046,12 @@ class InstitutionMixin:
965
1046
 
966
1047
  An entry carrying the school's entityID wins (several such entries are
967
1048
  the same school); otherwise the entry naming it. Only innermost
968
- candidates count (a list item and its link are one entry). Two entries
969
- with the same best name score, or only partial matches, are left to the
970
- user; the same text with the same link (an actual link, not two
971
- buttons) is one school (SAMS Sigma's "Recently Chosen" above its full
972
- list, 2026-11-01).
1049
+ candidates count (a list item and its link are one entry). Several entries
1050
+ with the same best name score are taken one after another, the orchestrator's
1051
+ ``institution_entry_turn`` saying which (user, 2026-11-22); only partial
1052
+ matches are left to the user; the same text with the same link (an actual
1053
+ link, not two buttons) is one school (SAMS Sigma's "Recently Chosen" above
1054
+ its full list, 2026-11-01).
973
1055
  """
974
1056
  try:
975
1057
  items = self._listed_entries(page)
@@ -980,6 +1062,17 @@ class InstitutionMixin:
980
1062
  entity_id = self._entity_id()
981
1063
 
982
1064
  scored = [(self._institution_entry_score(it, entity_id), it) for it in items if isinstance(it, dict)]
1065
+ # The school's name with another of its sign-ins than the saved one (its library's OpenAthens account beside
1066
+ # its CARSI sign-in: all Sage and JAMA list of a test school, its login page asking for a picture code; Windows
1067
+ # 2026-11-22). On such a page an entry by the school's name carrying nothing to tell its sign-in by may be that
1068
+ # one too (Sage's "Recent institution": what SeamlessAccess kept of an earlier choice of it): not clicked either.
1069
+ another = [it for score, it in scored if score == 1 and self._names_another_sign_in(str(it.get("ids") or ""), entity_id)
1070
+ and self._institution_match_score(str(it.get("t") or "")) >= 2]
1071
+ if another:
1072
+ result._another_sign_in_at = url
1073
+ another_here = bool(another) or self._same_address(str(getattr(result, "_another_sign_in_at", "") or ""), url)
1074
+ if another_here and not any(score == 4 for score, _ in scored):
1075
+ scored = [(1 if score >= 2 and not str(it.get("ids") or "").strip() else score, it) for score, it in scored]
983
1076
  if self.federation is not None:
984
1077
  # An entry its publisher marks as signing in no school (Elsevier's
985
1078
  # entries carry their route: IP, VPN or a work email, no entityID) is
@@ -988,15 +1081,18 @@ class InstitutionMixin:
988
1081
  and self.adapter.institution_entry_signs_in(unquote(str(it.get("ids") or ""))) is False]
989
1082
  if without:
990
1083
  scored = [(score, it) for score, it in scored if not any(it is w for w in without)]
991
- if not any(score >= 2 for score, _ in scored):
992
- if not self._list_settled(result, items):
993
- return False # the search may still be adding entries
994
- if getattr(result, "_institution_not_listed", False) is not True: # once, not every pass
995
- self._event(result, "auto_institution_not_found",
996
- f"{self.institution_query} (listed only without a school sign-in: "
997
- f"{len(without)} entr{'y' if len(without) == 1 else 'ies'}) @ {url}")
998
- result._institution_not_listed = True
999
- return False
1084
+ # Listed only so, the school has no route here: 没权限, another saved school tried at a batch's end.
1085
+ if (without or another_here) and not any(score >= 2 for score, _ in scored):
1086
+ if not self._list_settled(result, items):
1087
+ return False # the search may still be adding entries
1088
+ if getattr(result, "_institution_not_listed", False) is not True: # once, not every pass
1089
+ count = len(without) or max(len(another), 1)
1090
+ kind = "without a school sign-in" if without else "with another of its sign-ins"
1091
+ self._event(result, "auto_institution_not_found",
1092
+ f"{self.institution_query} (listed only {kind}: "
1093
+ f"{count} entr{'y' if count == 1 else 'ies'}) @ {url}")
1094
+ result._institution_not_listed = True
1095
+ return False
1000
1096
  top = max([score for score, _ in scored] or [0])
1001
1097
  best = [it for score, it in scored if score == top]
1002
1098
  if top < 2 and self.federation is not None and self._search_lists_no_school(page, result, url, scored):
@@ -1018,8 +1114,27 @@ class InstitutionMixin:
1018
1114
  # configured sign-in, by its entityID, the one this browser keeps the session of.
1019
1115
  if top >= 2 and len(best) > 1 and self._select_openathens_wayfinder(page, result):
1020
1116
  return True
1117
+ if top < 2 or len(best) < 2 or self._users_own_search(page):
1118
+ return False # the user typing a search of their own chooses (typed input is never replaced)
1119
+ # Several entries by the school's name, nothing else to tell them apart by (JAMA's search: a test school's name
1120
+ # two or three times, its CARSI sign-in and its library's proxy, Windows 2026-11-22): one after another in
1121
+ # the page's order, the next when the one before did not do (user, 2026-11-18 and 2026-11-22; the turn is
1122
+ # the orchestrator's, ``institution_entry_turn``).
1123
+ turn = int(self.config.get("institution_entry_turn") or 0)
1124
+ result._same_name_entries = len(best)
1125
+ if turn >= len(best):
1126
+ return False
1127
+ target = best[turn]
1128
+ self._event(result, "institution_same_name_choice",
1129
+ f"{turn + 1}/{len(best)}: {str(target.get('t') or '')[:60]} @ {url[:200]}")
1130
+ else:
1131
+ target = best[0]
1132
+ if (top in (2, 3) and entity_id and not str(target.get("ids") or "").strip()
1133
+ and self._searched_here(result, url) and not self._list_settled(result, items)):
1134
+ # An entry by the school's name carrying nothing to tell its sign-in by, where its name was searched: taken
1135
+ # once the list has settled, the search's own entries (each with its sign-in) shown by then (Sage's "Recent
1136
+ # institution" was clicked a second before its search showed that entry's other sign-in, Windows 2026-11-22).
1021
1137
  return False
1022
- target = best[0]
1023
1138
  before = str(getattr(page, "url", "") or "")
1024
1139
  try:
1025
1140
  marked = page.evaluate("""([sel, idx]) => {
@@ -1233,6 +1348,17 @@ class InstitutionMixin:
1233
1348
  label = re.sub(r"^\s*access through\s*", "", candidate["text"], flags=re.I)
1234
1349
  entries.append((self._institution_match_score(label), label,
1235
1350
  page.locator(f'[data-paper-search-remembered="{candidate["i"]}"]')))
1351
+ # A remembered entry whose link names another sign-in than the school's saved one: not clicked (Sage's
1352
+ # "Access through <the school>", idp=.../entity, sent the login straight back, Windows 2026-11-22).
1353
+ def link_of(entry: Any) -> str:
1354
+ try:
1355
+ return str(entry.get_attribute("href", timeout=1_000) or "")
1356
+ except Exception as exc:
1357
+ if not _is_browser_error(exc):
1358
+ raise
1359
+ return ""
1360
+ entries = [(1 if score >= 2 and self._names_another_sign_in(link_of(entry), self._entity_id()) else score,
1361
+ label, entry) for score, label, entry in entries]
1236
1362
  top = max((score for score, _, _ in entries), default=0)
1237
1363
  best = [(label, entry) for score, label, entry in entries if score == top]
1238
1364
  if top >= 2 and len(best) == 1:
@@ -1557,6 +1683,7 @@ class InstitutionMixin:
1557
1683
  self._route_hosts: set[str] = set()
1558
1684
  self._publisher_hosts: set[str] = set()
1559
1685
  self._route_away = False
1686
+ self._route_reached_school = False
1560
1687
  self._route_last_host = ""
1561
1688
  self._school_unreachable = ""
1562
1689
 
@@ -1591,17 +1718,26 @@ class InstitutionMixin:
1591
1718
  host = (urlparse(url).hostname or "").lower()
1592
1719
  if kind == "school":
1593
1720
  self._note_login_host(host)
1721
+ self._route_reached_school = True
1594
1722
  if kind in ("school", "route"):
1595
1723
  self._route_away = True
1596
1724
  if kind == "route" and self._names_identity_provider(url) and not self._login_service_host(host):
1597
1725
  # A publisher's or its platform's sign-in hub: its later pages are not the school's.
1598
1726
  self._route_hosts.add(host)
1599
1727
  elif kind == "publisher":
1600
- self._route_away = False
1728
+ if self._route_away and self._route_reached_school:
1729
+ # The login went to the school's side and came back to the publisher before the wait could see it:
1730
+ # it went round, as one the wait saw (_login_round_trip). Springer (Windows, 2026-11-24): the chosen
1731
+ # school, its federated sign-on, straight back to the article, still a preview; the wait ran out on
1732
+ # the article, 原因不明 · 没进入学校登录页 (login_not_reached), for 8 papers of journals not subscribed.
1733
+ result._login_round_trip = result._route_round_trip = True
1734
+ self._event(result, "login_round_trip_returned", f"{host} (by its route)")
1735
+ self._route_away = self._route_reached_school = False
1601
1736
  # Its other pages too (a journal site's sign-in step after its article).
1602
1737
  self._publisher_hosts.add(host)
1603
1738
  elif self._route_away and host not in self._route_hosts and host not in self._school_side_hosts:
1604
1739
  self._school_side_hosts.add(host)
1740
+ self._route_reached_school = True
1605
1741
  self._note_login_host(host)
1606
1742
  self._event(result, "school_side_host", f"{host} after {self._route_last_host}")
1607
1743
  self._route_last_host = host