papersearch 0.7.1 → 0.7.3

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 (126) hide show
  1. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  2. package/dist/capabilities/download/batch/batch.js +306 -12
  3. package/dist/capabilities/download/batch/batch.js.map +1 -1
  4. package/dist/capabilities/download/batch/batchFolder.js +1 -1
  5. package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
  6. package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -1
  7. package/dist/capabilities/download/batch/batchSummary.js +17 -8
  8. package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
  9. package/dist/capabilities/download/batch/journalKey.d.ts +12 -0
  10. package/dist/capabilities/download/batch/journalKey.d.ts.map +1 -0
  11. package/dist/capabilities/download/batch/journalKey.js +30 -0
  12. package/dist/capabilities/download/batch/journalKey.js.map +1 -0
  13. package/dist/capabilities/download/batch/networkLoss.d.ts +1 -1
  14. package/dist/capabilities/download/batch/networkLoss.js +1 -1
  15. package/dist/capabilities/download/content/markdown/shortfall.js +5 -5
  16. package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
  17. package/dist/capabilities/download/content/pdf/DownloadTier.d.ts +4 -0
  18. package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -1
  19. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -1
  20. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js +2 -0
  21. package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -1
  22. package/dist/capabilities/download/content/pdf/school.js +2 -0
  23. package/dist/capabilities/download/content/pdf/school.js.map +1 -1
  24. package/dist/capabilities/download/types.d.ts +4 -0
  25. package/dist/capabilities/download/types.d.ts.map +1 -1
  26. package/dist/cli.js +32 -9
  27. package/dist/cli.js.map +1 -1
  28. package/dist/infrastructure/runlog/failureClass.d.ts +16 -9
  29. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  30. package/dist/infrastructure/runlog/failureClass.js +64 -54
  31. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  32. package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
  33. package/dist/infrastructure/school/SchoolAttempt.js +61 -56
  34. package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
  35. package/dist/infrastructure/school/SchoolMcpClient.d.ts +9 -1
  36. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  37. package/dist/infrastructure/school/SchoolMcpClient.js +31 -1
  38. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  39. package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
  40. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  41. package/dist/infrastructure/school/SchoolReadiness.js +3 -0
  42. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  43. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  44. package/dist/infrastructure/school/SchoolResultNormalizer.js +5 -0
  45. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  46. package/dist/infrastructure/school/index.d.ts +1 -1
  47. package/dist/infrastructure/school/index.d.ts.map +1 -1
  48. package/dist/infrastructure/school/types.d.ts +19 -0
  49. package/dist/infrastructure/school/types.d.ts.map +1 -1
  50. package/dist/management/failures/index.d.ts +5 -2
  51. package/dist/management/failures/index.d.ts.map +1 -1
  52. package/dist/management/failures/index.js +21 -4
  53. package/dist/management/failures/index.js.map +1 -1
  54. package/dist/management/pro/activate.d.ts +36 -0
  55. package/dist/management/pro/activate.d.ts.map +1 -0
  56. package/dist/management/pro/activate.js +122 -0
  57. package/dist/management/pro/activate.js.map +1 -0
  58. package/dist/management/pro/install.d.ts +15 -0
  59. package/dist/management/pro/install.d.ts.map +1 -1
  60. package/dist/management/pro/install.js +39 -12
  61. package/dist/management/pro/install.js.map +1 -1
  62. package/dist/management/reports/index.d.ts +6 -0
  63. package/dist/management/reports/index.d.ts.map +1 -1
  64. package/dist/management/reports/index.js +6 -0
  65. package/dist/management/reports/index.js.map +1 -1
  66. package/dist/management/school/autoUpdate.d.ts.map +1 -1
  67. package/dist/management/school/autoUpdate.js +1 -0
  68. package/dist/management/school/autoUpdate.js.map +1 -1
  69. package/dist/management/school/cliProgress.d.ts.map +1 -1
  70. package/dist/management/school/cliProgress.js +1 -0
  71. package/dist/management/school/cliProgress.js.map +1 -1
  72. package/dist/management/school/settingsWindow.d.ts +1 -0
  73. package/dist/management/school/settingsWindow.d.ts.map +1 -1
  74. package/dist/management/school/settingsWindow.js +2 -0
  75. package/dist/management/school/settingsWindow.js.map +1 -1
  76. package/dist/management/updates/selfUpdate.d.ts +86 -0
  77. package/dist/management/updates/selfUpdate.d.ts.map +1 -0
  78. package/dist/management/updates/selfUpdate.js +194 -0
  79. package/dist/management/updates/selfUpdate.js.map +1 -0
  80. package/package.json +1 -1
  81. package/school/paper_search_school/adapters/annual_reviews/__init__.py +1 -0
  82. package/school/paper_search_school/adapters/base.py +4 -0
  83. package/school/paper_search_school/adapters/ieee/__init__.py +1 -0
  84. package/school/paper_search_school/adapters/oup/__init__.py +20 -0
  85. package/school/paper_search_school/adapters/sage/__init__.py +4 -1
  86. package/school/paper_search_school/adapters/taylor_francis/__init__.py +3 -0
  87. package/school/paper_search_school/adapters/thieme/__init__.py +4 -2
  88. package/school/paper_search_school/assets/capsule.html +1044 -243
  89. package/school/paper_search_school/assets/capsule_en.json +320 -74
  90. package/school/paper_search_school/assets/capsule_fr.json +1309 -0
  91. package/school/paper_search_school/assets/capsule_ja.json +1309 -0
  92. package/school/paper_search_school/assets/capsule_ko.json +1309 -0
  93. package/school/paper_search_school/assets/capsule_zh-Hant.json +2436 -0
  94. package/school/paper_search_school/cli.py +15 -1
  95. package/school/paper_search_school/cold_start.py +82 -9
  96. package/school/paper_search_school/config.py +2 -0
  97. package/school/paper_search_school/download_diagnostics.py +4 -4
  98. package/school/paper_search_school/engine/access_rules.py +3 -2
  99. package/school/paper_search_school/engine/batch.py +12 -4
  100. package/school/paper_search_school/engine/batch_access.py +21 -9
  101. package/school/paper_search_school/engine/batch_capture.py +36 -2
  102. package/school/paper_search_school/engine/batch_diagnostics.py +1 -1
  103. package/school/paper_search_school/engine/batch_institution.py +171 -29
  104. package/school/paper_search_school/engine/batch_login.py +65 -1
  105. package/school/paper_search_school/engine/batch_waits.py +22 -8
  106. package/school/paper_search_school/engine/bridge.py +27 -3
  107. package/school/paper_search_school/engine/router.py +2 -1
  108. package/school/paper_search_school/i18n.py +46 -22
  109. package/school/paper_search_school/orchestrator.py +90 -12
  110. package/school/paper_search_school/pro_status.py +54 -63
  111. package/school/paper_search_school/progress_capsule.py +180 -24
  112. package/school/paper_search_school/progress_reporter.py +68 -13
  113. package/school/paper_search_school/progress_view.py +4 -3
  114. package/school/paper_search_school/publishers/builtin/sage.json +4 -2
  115. package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
  116. package/school/paper_search_school/school_login.py +18 -4
  117. package/school/paper_search_school/school_switch.py +84 -0
  118. package/school/paper_search_school/school_test.py +335 -0
  119. package/school/paper_search_school/server.py +21 -3
  120. package/school/paper_search_school/updates.py +222 -0
  121. package/school/paper_search_school/user_settings.py +8 -3
  122. package/skills/paper-search/SKILL.md +1 -1
  123. package/skills/paper-search/references/browser-download.md +7 -9
  124. package/skills/paper-search/references/cli-contract.md +1 -1
  125. package/skills/paper-search/references/publisher-support.md +2 -2
  126. package/skills/paper-search/references/school-setup.md +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/download/batch/batch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAMnE,OAAO,KAAK,EAAE,aAA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AgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,uBAAuB,EAAE,CAAC;CAClC;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,2BAA2B,GAAG;IAAE,KAAK,EAAE,qBAAqB,CAAA;CAAE,EACvE,KAAK,EAAE,YAAY,EAAE,EACrB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,0BAA0B,CAAC,CAIrC;AAkGD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAc,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AA4F9C,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAEjE;AA8KD,6EAA6E;AAC7E,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,aAAa,EACvB,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAkD,EACzE,WAAW,GAAE,CAAC,OAAO,CAAC,EAAE,aAAa,KAAK,YAAY,EAA+B,EACrF,KAAK,GAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAQ,EAC3C,MAAM,GAAE,MAAM,OAAO,CAAC,OAAO,CAAoB,GAChD,OAAO,CAAC,mBAAmB,CAAC,CAsG9B"}
@@ -1,9 +1,10 @@
1
1
  import { resolveDownloadPath } from "../../../config/ConfigService.js";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { RunLedger } from "../../../infrastructure/runlog/RunLedger.js";
4
- import { FAILURE_CLASS_NAMES, } from "../../../infrastructure/runlog/failureClass.js";
4
+ import { classifyFailureCode, FAILURE_CLASS_NAMES, } from "../../../infrastructure/runlog/failureClass.js";
5
5
  import { createDefaultDownloadTiers, downloadWithFallback, } from "../content/pdf/OpenAccessFallbackService.js";
6
6
  import { schoolAttemptDetails, schoolShortReason } from "../../../infrastructure/school/index.js";
7
+ import { journalOfDoi, takeNext } from "./journalKey.js";
7
8
  import { downloadSupplementsOnly, filesPastNetworkLoss } from "../content/supplements/fetch.js";
8
9
  import { supplementShortfall } from "../content/supplements/shortfall.js";
9
10
  import { fulltextPageVisit } from "../content/markdown/pageVisit.js";
@@ -191,6 +192,58 @@ const STOP_NOTICE = "[批量] 已在进度窗口终止任务,剩下的篇目
191
192
  export function batchStopped(result) {
192
193
  return !!result.stopped || result.items.some((item) => stoppedByUser(item) || item.attempts.some((attempt) => attempt.code === "login_paused"));
193
194
  }
195
+ /**
196
+ * 没权限 (FailureClass no_access) at the school's stage: the publisher refused the signed-in school, the school's
197
+ * sign-in is not enabled for the publisher, the publisher has no route for it, or the user marked the journal as
198
+ * without access. Another saved school may have it (没权限时换下一所学校, user 2026-11-22: every paper under 没权限).
199
+ */
200
+ function withoutAccess(result) {
201
+ if (!result || result.status === "ok")
202
+ return false;
203
+ const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
204
+ return school?.status === "error" && classifyFailureCode(school.code) === "no_access";
205
+ }
206
+ /**
207
+ * 原因不明 (FailureClass unexplained) at the school's stage: tried once more at the batch's end, with the school it had,
208
+ * before any other school (user, 2026-11-22: "原因不明的也最后再试一次"); not a paper the user stopped.
209
+ */
210
+ function unexplainedFailure(result) {
211
+ if (!result || result.status === "ok" || stoppedByUser(result))
212
+ return false;
213
+ const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
214
+ return school?.status === "error" && classifyFailureCode(school.code) === "unexplained";
215
+ }
216
+ /** The other saved schools a batch's papers without access go to at its end: none for a batch given its school. */
217
+ async function schoolsAfterDefault(backend, options) {
218
+ if (options.school?.trim() || !backend?.schoolSwitch)
219
+ return [];
220
+ return (await backend.schoolSwitch().catch(() => undefined))?.schools.slice(1) ?? [];
221
+ }
222
+ /**
223
+ * 没权限时换下一所学校 at a batch's end (PaperSearch Pro; user, 2026-11-22): the papers still without access go to each
224
+ * other saved school in turn, all of them with one before the next, so that the school's login is switched once, not at
225
+ * every paper (switching to and fro had a school's login ask for a picture code, Windows 2026-11-22). ``visit`` tries
226
+ * one paper with a school.
227
+ */
228
+ async function laterSchools(schools, waiting, announce, visit, stopped) {
229
+ for (const school of schools) {
230
+ const offsets = waiting();
231
+ if (!offsets.length || stopped())
232
+ return;
233
+ await announce(school, offsets.length);
234
+ for (const offset of offsets) {
235
+ if (stopped())
236
+ return;
237
+ await visit(offset, school);
238
+ }
239
+ }
240
+ }
241
+ /** A paper without access with each of ``count`` schools: its last school stage says so (N 所学校都没有权限). */
242
+ function triedSchools(result, count) {
243
+ const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
244
+ if (school && count > 1)
245
+ school.schools = count;
246
+ }
194
247
  /** The attempt recorded for an item the batch did not reach because the user stopped it. */
195
248
  function notReached() {
196
249
  return { stage: "entitled_access", status: "skipped", message: "已终止任务,未下载", code: "batch_stopped" };
@@ -474,17 +527,23 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
474
527
  let succeeded = 0;
475
528
  let failed = 0;
476
529
  let away = false;
530
+ // 没权限时换下一所学校 (PaperSearch Pro): papers without access wait for the other saved schools, tried at the end, one
531
+ // school at a time (``laterSchools``, user 2026-11-22).
532
+ let turns;
533
+ const otherSchools = () => (turns ??= schoolsAfterDefault(backend, options));
534
+ const waiting = new Map();
535
+ const schoolsTried = new Map();
536
+ /** Papers failed for a reason not known, waiting for their one more try at the end (user, 2026-11-22). */
537
+ const unexplainedYet = new Map();
538
+ let stopped = false;
477
539
  for (const [offset, item] of options.items.entries()) {
478
540
  const index = offset + 1;
479
541
  const request = itemOptions(item, options);
480
542
  const entry = runItem(index, request);
481
543
  log(`[批量] 第 ${index}/${total} 篇:${request.doi || request.paperId}`);
482
- const batch = { id: batchId, index, total, done: offset, succeeded, failed };
544
+ // Papers waiting for the end (without access, 原因不明) are not done yet: the counts are of those finished.
545
+ const batch = { id: batchId, index, total, done: succeeded + failed, succeeded, failed };
483
546
  const result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend)), log, pause, backend), watch);
484
- if (result.status === "ok")
485
- succeeded += 1;
486
- else
487
- failed += 1;
488
547
  if (!away && waitedOutOnUser(result)) {
489
548
  away = true;
490
549
  log(AWAY_NOTICE);
@@ -495,13 +554,33 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
495
554
  if (!stoppedByUser(result)) {
496
555
  await markdownPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), searchers, pageVisit(backend, { ...request, batch }, log, pause), watch);
497
556
  }
498
- await reportBatchItem({ ...request, batch }, finished, backend);
499
- ledger?.item(entry, finished);
500
557
  items.push(finished);
558
+ if (withoutAccess(finished) && !stoppedByUser(finished) && (await otherSchools()).length) {
559
+ // Not finished: it waits for the other schools at the end.
560
+ waiting.set(offset, entry);
561
+ papers.set(offset, batchPaper(request, finished, "school", content));
562
+ await papers.send();
563
+ continue;
564
+ }
565
+ if (unexplainedFailure(finished)) {
566
+ // Not finished: once more at the end, with this school.
567
+ unexplainedYet.set(offset, entry);
568
+ papers.set(offset, batchPaper(request, finished, "school", content));
569
+ await papers.send();
570
+ continue;
571
+ }
572
+ if (result.status === "ok")
573
+ succeeded += 1;
574
+ else
575
+ failed += 1;
576
+ // The window's end when the last paper is finished, not the last in the list (some wait for the end).
577
+ await reportBatchItem({ ...request, batch: { ...batch, index: batch.done + 1 } }, finished, backend);
578
+ ledger?.item(entry, finished);
501
579
  papers.set(offset, batchPaper(request, finished, undefined, content));
502
580
  if (publisherBlocked(result))
503
581
  log(blockedNotice(request.doi || request.paperId));
504
582
  if (stoppedByUser(finished)) {
583
+ stopped = true;
505
584
  for (const [rest, restItem] of options.items.entries()) {
506
585
  if (rest <= offset)
507
586
  continue;
@@ -516,6 +595,77 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
516
595
  }
517
596
  await papers.send();
518
597
  }
598
+ /** A paper's school stage once more (another saved school when given), its files and Markdown when it comes. */
599
+ const again = async (offset, entry, school) => {
600
+ const request = { ...itemOptions(options.items[offset], options), ...(school ? { school: school.entityId } : {}) };
601
+ const batch = { id: batchId, index: offset + 1, total, done: succeeded + failed, succeeded, failed };
602
+ log(school ? `[批量] 换${school.name}:${request.doi || request.paperId}` : `[批量] 再试一次:${request.doi || request.paperId}`);
603
+ const result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend).filter((tier) => tier.stage === "entitled_access")), log, pause, backend), watch);
604
+ const before = items[offset];
605
+ const finished = itemResult({ ...result, attempts: [...before.attempts, ...result.attempts],
606
+ ...(before.markdown ? { markdown: before.markdown } : {}) }, offset + 1, request);
607
+ items[offset] = finished;
608
+ if (result.status === "ok") {
609
+ await filesPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), backend, searchers, watch);
610
+ if (finished.markdown?.status !== "ok") {
611
+ await markdownPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), searchers, pageVisit(backend, { ...request, batch }, log, pause), watch);
612
+ }
613
+ }
614
+ if (stoppedByUser(result))
615
+ stopped = true;
616
+ return finished;
617
+ };
618
+ /** A paper finished at the end: counted, recorded, shown. */
619
+ const finish = async (offset, entry) => {
620
+ const request = itemOptions(options.items[offset], options);
621
+ const done = succeeded + failed;
622
+ const batch = { id: batchId, index: done + 1, total, done, succeeded, failed };
623
+ if (items[offset].status === "ok")
624
+ succeeded += 1;
625
+ else
626
+ failed += 1;
627
+ await reportBatchItem({ ...request, batch }, items[offset], backend);
628
+ ledger?.item(entry, items[offset]);
629
+ papers.set(offset, batchPaper(request, items[offset], undefined, content));
630
+ await papers.send();
631
+ };
632
+ // 原因不明 once more, with this school, before any other school (user, 2026-11-22).
633
+ if (unexplainedYet.size && !stopped) {
634
+ log(`[批量] 原因不明的 ${unexplainedYet.size} 篇再试一次`);
635
+ ledger?.phase(`原因不明的 ${unexplainedYet.size} 篇再试一次`);
636
+ for (const [offset, entry] of [...unexplainedYet]) {
637
+ if (stopped)
638
+ break;
639
+ const finished = await again(offset, entry);
640
+ unexplainedYet.delete(offset);
641
+ if (!stopped && withoutAccess(finished) && (await otherSchools()).length)
642
+ waiting.set(offset, entry);
643
+ else
644
+ await finish(offset, entry);
645
+ }
646
+ }
647
+ for (const [offset, entry] of unexplainedYet)
648
+ await finish(offset, entry);
649
+ // The papers without access go to the other saved schools, one school at a time.
650
+ if (waiting.size && !stopped) {
651
+ await laterSchools(await otherSchools(), () => [...waiting.keys()], async (school, count) => {
652
+ log(`[批量] 没权限的 ${count} 篇换${school.name}再试`);
653
+ ledger?.phase(`没权限的 ${count} 篇换${school.name}再试`);
654
+ }, async (offset, school) => {
655
+ const entry = waiting.get(offset);
656
+ const finished = await again(offset, entry, school);
657
+ schoolsTried.set(offset, (schoolsTried.get(offset) ?? 1) + 1);
658
+ if (!stopped && withoutAccess(finished)) {
659
+ triedSchools(finished, schoolsTried.get(offset));
660
+ return;
661
+ }
662
+ waiting.delete(offset);
663
+ await finish(offset, entry);
664
+ }, () => stopped);
665
+ }
666
+ // Without access with every school (or the batch stopped first): failed.
667
+ for (const [offset, entry] of waiting)
668
+ await finish(offset, entry);
519
669
  await papers.send(true);
520
670
  ledger?.close();
521
671
  return summary("per_item", batchId, items, {
@@ -858,13 +1008,33 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
858
1008
  forward?.(record);
859
1009
  } };
860
1010
  };
1011
+ // 没权限时换下一所学校 (PaperSearch Pro): the other saved schools, asked once a paper has gone without access (the
1012
+ // backend the batch has by then can say). Such papers wait, not finished, and go to them at the end, all of them with
1013
+ // one school before the next (``laterSchools``, user 2026-11-22).
1014
+ let turns;
1015
+ const otherSchools = () => (turns ??= schoolsAfterDefault(backend, options));
1016
+ /** Papers without access with the schools tried so far, waiting for the next one. */
1017
+ const withoutAccessYet = new Set();
1018
+ /** Papers failed for a reason not known, waiting for their one more try at the end. */
1019
+ const unexplainedYet = new Set();
1020
+ /** Each waiting paper's schools tried, the default one counted. */
1021
+ const schoolsTried = new Map();
1022
+ // One journal's papers one after another when the backend says so (more than one school taking part, user
1023
+ // 2026-11-21; kept with the switch at the end, user 2026-11-22). Asked until the backend has run a paper and can say.
1024
+ let groupJournals;
1025
+ let lastJournal = "";
861
1026
  const entitledLane = async () => {
862
1027
  for (;;) {
863
1028
  while (!queue.length && openRunning && !stopped)
864
1029
  await new Promise((resume) => { wake = resume; });
865
- const offset = stopped ? undefined : queue.shift();
1030
+ if (groupJournals === undefined && backend?.schoolSwitch) {
1031
+ groupJournals = (await backend.schoolSwitch().catch(() => undefined))?.group;
1032
+ }
1033
+ const offset = stopped ? undefined
1034
+ : takeNext(queue, (at) => journalOfDoi(requests[at].doi), lastJournal, groupJournals === true);
866
1035
  if (offset === undefined)
867
1036
  return;
1037
+ lastJournal = journalOfDoi(requests[offset].doi);
868
1038
  if (held.has(publisherOf(offset))) {
869
1039
  held.get(publisherOf(offset)).push(offset);
870
1040
  continue;
@@ -879,15 +1049,21 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
879
1049
  continue;
880
1050
  }
881
1051
  const request = requests[offset];
882
- const step = succeeded + failed + 1;
1052
+ // Papers waiting for the end (without access, 原因不明) counted too: the log goes 1/7, 2/7 … as the window does
1053
+ // (Windows 2026-11-22: every line said 1/7 while the papers waited).
1054
+ const step = succeeded + failed + withoutAccessYet.size + unexplainedYet.size + 1;
883
1055
  log(openRunning
884
1056
  ? `[批量] 机构下载第 ${step} 篇(开放来源还在查):${id(offset)}`
885
1057
  : `[批量] 机构下载 ${step}/${missed.length}:${id(offset)}`);
886
1058
  const done = settledOk() + failed;
887
- const batch = { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed };
1059
+ // Its place among the papers gone through, those waiting for the end counted (the window's "k / N" goes on);
1060
+ // the counts are of those finished.
1061
+ const batch = { id: batchId, index: done + withoutAccessYet.size + unexplainedYet.size + 1, total, done,
1062
+ succeeded: settledOk(), failed };
888
1063
  let result;
889
1064
  try {
890
- result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadBatchItem(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]), offset), createTiers(backend).filter((tier) => tier.stage === "entitled_access" || mode !== "entitled_only" && tier.stage === "preprint"), backend), log, pause, backend), watch);
1065
+ // Reported to the window once it is known whether the paper waits for the end (``reportBatchItem`` below).
1066
+ result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]), offset), createTiers(backend).filter((tier) => tier.stage === "entitled_access" || mode !== "entitled_only" && tier.stage === "preprint")), log, pause, backend), watch);
891
1067
  }
892
1068
  catch (error) {
893
1069
  result = laneError("entitled_access", error);
@@ -923,11 +1099,23 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
923
1099
  else if (holding) {
924
1100
  hold(offset);
925
1101
  }
1102
+ else if (withoutAccess(result) && !stoppedByUser(result) && (await otherSchools()).length) {
1103
+ withoutAccessYet.add(offset);
1104
+ settle(offset, "school");
1105
+ }
1106
+ else if (unexplainedFailure(result)) {
1107
+ unexplainedYet.add(offset);
1108
+ settle(offset, "school");
1109
+ }
926
1110
  else {
927
1111
  failed += 1;
928
1112
  record(offset);
929
1113
  settle(offset);
930
1114
  }
1115
+ // The window's line, not for a paper that waits for the end (it would close the batch early when last).
1116
+ if (!withoutAccessYet.has(offset) && !unexplainedYet.has(offset)) {
1117
+ await reportBatchItem({ ...request, batch: { ...batch, index: batch.done + 1 } }, result, backend);
1118
+ }
931
1119
  if (publisherBlocked(result))
932
1120
  log(blockedNotice(id(offset)));
933
1121
  if (stoppedByUser(result)) {
@@ -972,6 +1160,112 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
972
1160
  await entitledLane();
973
1161
  }
974
1162
  }
1163
+ /** A paper's school stage once more, with another saved school when given; merged into its result. */
1164
+ const visitAgain = async (offset, school) => {
1165
+ const request = { ...requests[offset], ...(school ? { school: school.entityId } : {}) };
1166
+ const done = settledOk() + failed;
1167
+ const batch = { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed };
1168
+ log(school ? `[批量] 换${school.name}:${id(offset)}` : `[批量] 再试一次:${id(offset)}`);
1169
+ let result;
1170
+ try {
1171
+ result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]), offset), createTiers(backend).filter((tier) => tier.stage === "entitled_access")), log, pause, backend), watch);
1172
+ }
1173
+ catch (error) {
1174
+ result = laneError("entitled_access", error);
1175
+ log(`[批量] 机构下载出错(${id(offset)}):${result.attempts[0].message}`);
1176
+ }
1177
+ const before = results[offset];
1178
+ const markdown = result.markdown ?? before.markdown;
1179
+ results[offset] = itemResult({
1180
+ ...result,
1181
+ attempts: [...before.attempts, ...result.attempts],
1182
+ ...(result.review ?? before.review ? { review: result.review ?? before.review } : {}),
1183
+ ...(markdown ? { markdown } : {}),
1184
+ }, offset + 1, requests[offset]);
1185
+ const item = results[offset];
1186
+ // Its Markdown from the page this visit saved, unless the open sources gave it already.
1187
+ if (wantsMarkdown && result.status === "ok" && item.markdown?.status !== "ok") {
1188
+ await markdownPastNetworkLoss(item, recorded({ ...request, batch }, ledger, entries[offset]), searchers, pageVisit(backend, { ...request, batch, ...(away ? { shortUserWait: true } : {}) }, log, pause), watch);
1189
+ }
1190
+ if (stoppedByUser(result))
1191
+ stopped = true;
1192
+ if (publisherBlocked(result))
1193
+ log(blockedNotice(id(offset)));
1194
+ return item;
1195
+ };
1196
+ /** The window's line for a paper finished at the end (the counts before it, as ``reportBatchItem`` takes them). */
1197
+ const reportSettled = async (offset) => {
1198
+ const done = settledOk() + failed;
1199
+ await reportBatchItem({ ...requests[offset], batch: { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed } }, results[offset], backend);
1200
+ };
1201
+ // 原因不明 once more, the default school still signed in, before any other school (user, 2026-11-22).
1202
+ if (unexplainedYet.size && !stopped) {
1203
+ log(`[批量] 原因不明的 ${unexplainedYet.size} 篇再试一次`);
1204
+ ledger?.phase(`原因不明的 ${unexplainedYet.size} 篇再试一次`);
1205
+ for (const offset of [...unexplainedYet]) {
1206
+ if (stopped)
1207
+ break;
1208
+ const item = await visitAgain(offset);
1209
+ unexplainedYet.delete(offset);
1210
+ if (!stopped && item.status !== "ok" && withoutAccess(item) && (await otherSchools()).length) {
1211
+ withoutAccessYet.add(offset);
1212
+ }
1213
+ else {
1214
+ await reportSettled(offset);
1215
+ if (item.status === "ok")
1216
+ succeeded += 1;
1217
+ else
1218
+ failed += 1;
1219
+ record(offset);
1220
+ settle(offset);
1221
+ }
1222
+ await sendPapers();
1223
+ }
1224
+ }
1225
+ for (const offset of unexplainedYet) {
1226
+ await reportSettled(offset);
1227
+ failed += 1;
1228
+ record(offset);
1229
+ }
1230
+ unexplainedYet.clear();
1231
+ // The papers without access go to the other saved schools, one school at a time.
1232
+ const withSchool = async (offset, school) => {
1233
+ const item = await visitAgain(offset, school);
1234
+ schoolsTried.set(offset, (schoolsTried.get(offset) ?? 1) + 1);
1235
+ if (!stopped && withoutAccess(item)) {
1236
+ triedSchools(item, schoolsTried.get(offset));
1237
+ }
1238
+ else {
1239
+ withoutAccessYet.delete(offset);
1240
+ await reportSettled(offset);
1241
+ if (item.status === "ok")
1242
+ succeeded += 1;
1243
+ else
1244
+ failed += 1;
1245
+ record(offset);
1246
+ settle(offset);
1247
+ }
1248
+ await sendPapers();
1249
+ };
1250
+ if (withoutAccessYet.size && !stopped) {
1251
+ await laterSchools(await otherSchools(), () => [...withoutAccessYet], async (school, count) => {
1252
+ log(`[批量] 没权限的 ${count} 篇换${school.name}再试`);
1253
+ ledger?.phase(`没权限的 ${count} 篇换${school.name}再试`);
1254
+ if (!backend?.reportBatchProgress)
1255
+ return;
1256
+ const update = { id: batchId, total, done: settledOk() + failed, succeeded: settledOk(), failed, current: "",
1257
+ finished: false, phase: `没权限,换${school.name}` };
1258
+ reports = reports.then(() => backend.reportBatchProgress(update)).catch(() => false);
1259
+ await reports;
1260
+ }, withSchool, () => stopped);
1261
+ }
1262
+ // Without access with every school (or the batch stopped first): failed.
1263
+ for (const offset of withoutAccessYet) {
1264
+ await reportSettled(offset);
1265
+ failed += 1;
1266
+ record(offset);
1267
+ }
1268
+ withoutAccessYet.clear();
975
1269
  await reports;
976
1270
  // Stopped in the window: the items neither lane reached end as not downloaded, the held as paused.
977
1271
  if (stopped) {