@alisio/plugin-thesis 0.1.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 (547) hide show
  1. package/.agents/agents/thesis-architect.md +38 -0
  2. package/.agents/agents/thesis-coordinator.md +39 -0
  3. package/.agents/agents/thesis-editor.md +35 -0
  4. package/.agents/agents/thesis-evidence-auditor.md +37 -0
  5. package/.agents/agents/thesis-librarian.md +38 -0
  6. package/.agents/agents/thesis-methodologist.md +39 -0
  7. package/.agents/agents/thesis-reviewer.md +36 -0
  8. package/.agents/agents/thesis-writer.md +38 -0
  9. package/.agents/skills/thesis-build/SKILL.md +48 -0
  10. package/.agents/skills/thesis-citations/SKILL.md +49 -0
  11. package/.agents/skills/thesis-csl-authoring/SKILL.md +48 -0
  12. package/.agents/skills/thesis-editing/SKILL.md +49 -0
  13. package/.agents/skills/thesis-evidence/SKILL.md +48 -0
  14. package/.agents/skills/thesis-figures/SKILL.md +50 -0
  15. package/.agents/skills/thesis-institution-norms/SKILL.md +50 -0
  16. package/.agents/skills/thesis-intake/SKILL.md +48 -0
  17. package/.agents/skills/thesis-math/SKILL.md +48 -0
  18. package/.agents/skills/thesis-methodology/SKILL.md +49 -0
  19. package/.agents/skills/thesis-outline/SKILL.md +48 -0
  20. package/.agents/skills/thesis-policy/SKILL.md +48 -0
  21. package/.agents/skills/thesis-review/SKILL.md +49 -0
  22. package/.agents/skills/thesis-search/SKILL.md +47 -0
  23. package/.agents/skills/thesis-writing/SKILL.md +52 -0
  24. package/LICENSE +21 -0
  25. package/README.es.md +242 -0
  26. package/README.md +235 -0
  27. package/THIRD_PARTY_NOTICES.md +94 -0
  28. package/assets/architecture.svg +1 -0
  29. package/assets/evidence-pipeline.svg +1 -0
  30. package/assets/lifecycle.svg +1 -0
  31. package/assets/policy-resolution.svg +1 -0
  32. package/cover.webp +0 -0
  33. package/dist/authoring.d.ts +30 -0
  34. package/dist/authoring.d.ts.map +1 -0
  35. package/dist/authoring.js +681 -0
  36. package/dist/authoring.js.map +1 -0
  37. package/dist/brief.d.ts +40 -0
  38. package/dist/brief.d.ts.map +1 -0
  39. package/dist/brief.js +566 -0
  40. package/dist/brief.js.map +1 -0
  41. package/dist/cache.d.ts +8 -0
  42. package/dist/cache.d.ts.map +1 -0
  43. package/dist/cache.js +20 -0
  44. package/dist/cache.js.map +1 -0
  45. package/dist/checks/brief.d.ts +5 -0
  46. package/dist/checks/brief.d.ts.map +1 -0
  47. package/dist/checks/brief.js +38 -0
  48. package/dist/checks/brief.js.map +1 -0
  49. package/dist/checks/citations.d.ts +14 -0
  50. package/dist/checks/citations.d.ts.map +1 -0
  51. package/dist/checks/citations.js +87 -0
  52. package/dist/checks/citations.js.map +1 -0
  53. package/dist/checks/claims.d.ts +16 -0
  54. package/dist/checks/claims.d.ts.map +1 -0
  55. package/dist/checks/claims.js +147 -0
  56. package/dist/checks/claims.js.map +1 -0
  57. package/dist/checks/closing.d.ts +20 -0
  58. package/dist/checks/closing.d.ts.map +1 -0
  59. package/dist/checks/closing.js +168 -0
  60. package/dist/checks/closing.js.map +1 -0
  61. package/dist/checks/design.d.ts +5 -0
  62. package/dist/checks/design.d.ts.map +1 -0
  63. package/dist/checks/design.js +107 -0
  64. package/dist/checks/design.js.map +1 -0
  65. package/dist/checks/document.d.ts +17 -0
  66. package/dist/checks/document.d.ts.map +1 -0
  67. package/dist/checks/document.js +213 -0
  68. package/dist/checks/document.js.map +1 -0
  69. package/dist/checks/evidence.d.ts +7 -0
  70. package/dist/checks/evidence.d.ts.map +1 -0
  71. package/dist/checks/evidence.js +133 -0
  72. package/dist/checks/evidence.js.map +1 -0
  73. package/dist/checks/hygiene.d.ts +5 -0
  74. package/dist/checks/hygiene.d.ts.map +1 -0
  75. package/dist/checks/hygiene.js +37 -0
  76. package/dist/checks/hygiene.js.map +1 -0
  77. package/dist/checks/index.d.ts +21 -0
  78. package/dist/checks/index.d.ts.map +1 -0
  79. package/dist/checks/index.js +98 -0
  80. package/dist/checks/index.js.map +1 -0
  81. package/dist/checks/language.d.ts +14 -0
  82. package/dist/checks/language.d.ts.map +1 -0
  83. package/dist/checks/language.js +73 -0
  84. package/dist/checks/language.js.map +1 -0
  85. package/dist/checks/outline.d.ts +25 -0
  86. package/dist/checks/outline.d.ts.map +1 -0
  87. package/dist/checks/outline.js +214 -0
  88. package/dist/checks/outline.js.map +1 -0
  89. package/dist/checks/policy.d.ts +5 -0
  90. package/dist/checks/policy.d.ts.map +1 -0
  91. package/dist/checks/policy.js +129 -0
  92. package/dist/checks/policy.js.map +1 -0
  93. package/dist/checks/project.d.ts +65 -0
  94. package/dist/checks/project.d.ts.map +1 -0
  95. package/dist/checks/project.js +203 -0
  96. package/dist/checks/project.js.map +1 -0
  97. package/dist/checks/styles.d.ts +12 -0
  98. package/dist/checks/styles.d.ts.map +1 -0
  99. package/dist/checks/styles.js +67 -0
  100. package/dist/checks/styles.js.map +1 -0
  101. package/dist/checks/writing.d.ts +6 -0
  102. package/dist/checks/writing.d.ts.map +1 -0
  103. package/dist/checks/writing.js +115 -0
  104. package/dist/checks/writing.js.map +1 -0
  105. package/dist/chrome/detect.d.ts +19 -0
  106. package/dist/chrome/detect.d.ts.map +1 -0
  107. package/dist/chrome/detect.js +116 -0
  108. package/dist/chrome/detect.js.map +1 -0
  109. package/dist/claims.d.ts +19 -0
  110. package/dist/claims.d.ts.map +1 -0
  111. package/dist/claims.js +99 -0
  112. package/dist/claims.js.map +1 -0
  113. package/dist/cli.d.ts +11 -0
  114. package/dist/cli.d.ts.map +1 -0
  115. package/dist/cli.js +262 -0
  116. package/dist/cli.js.map +1 -0
  117. package/dist/context.d.ts +55 -0
  118. package/dist/context.d.ts.map +1 -0
  119. package/dist/context.js +62 -0
  120. package/dist/context.js.map +1 -0
  121. package/dist/coordinator.d.ts +139 -0
  122. package/dist/coordinator.d.ts.map +1 -0
  123. package/dist/coordinator.js +710 -0
  124. package/dist/coordinator.js.map +1 -0
  125. package/dist/delegate.d.ts +34 -0
  126. package/dist/delegate.d.ts.map +1 -0
  127. package/dist/delegate.js +105 -0
  128. package/dist/delegate.js.map +1 -0
  129. package/dist/diffguard.d.ts +24 -0
  130. package/dist/diffguard.d.ts.map +1 -0
  131. package/dist/diffguard.js +92 -0
  132. package/dist/diffguard.js.map +1 -0
  133. package/dist/doctor.d.ts +34 -0
  134. package/dist/doctor.d.ts.map +1 -0
  135. package/dist/doctor.js +155 -0
  136. package/dist/doctor.js.map +1 -0
  137. package/dist/draft.d.ts +64 -0
  138. package/dist/draft.d.ts.map +1 -0
  139. package/dist/draft.js +801 -0
  140. package/dist/draft.js.map +1 -0
  141. package/dist/figure.d.ts +13 -0
  142. package/dist/figure.d.ts.map +1 -0
  143. package/dist/figure.js +143 -0
  144. package/dist/figure.js.map +1 -0
  145. package/dist/finalize.d.ts +29 -0
  146. package/dist/finalize.d.ts.map +1 -0
  147. package/dist/finalize.js +230 -0
  148. package/dist/finalize.js.map +1 -0
  149. package/dist/index.d.ts +33 -0
  150. package/dist/index.d.ts.map +1 -0
  151. package/dist/index.js +206 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/intake.d.ts +57 -0
  154. package/dist/intake.d.ts.map +1 -0
  155. package/dist/intake.js +772 -0
  156. package/dist/intake.js.map +1 -0
  157. package/dist/labels.d.ts +50 -0
  158. package/dist/labels.d.ts.map +1 -0
  159. package/dist/labels.js +98 -0
  160. package/dist/labels.js.map +1 -0
  161. package/dist/outline.d.ts +45 -0
  162. package/dist/outline.d.ts.map +1 -0
  163. package/dist/outline.js +148 -0
  164. package/dist/outline.js.map +1 -0
  165. package/dist/pack-commands.d.ts +18 -0
  166. package/dist/pack-commands.d.ts.map +1 -0
  167. package/dist/pack-commands.js +397 -0
  168. package/dist/pack-commands.js.map +1 -0
  169. package/dist/package-paths.d.ts +8 -0
  170. package/dist/package-paths.d.ts.map +1 -0
  171. package/dist/package-paths.js +13 -0
  172. package/dist/package-paths.js.map +1 -0
  173. package/dist/policy/context.d.ts +19 -0
  174. package/dist/policy/context.d.ts.map +1 -0
  175. package/dist/policy/context.js +62 -0
  176. package/dist/policy/context.js.map +1 -0
  177. package/dist/policy/ethics.d.ts +59 -0
  178. package/dist/policy/ethics.d.ts.map +1 -0
  179. package/dist/policy/ethics.js +106 -0
  180. package/dist/policy/ethics.js.map +1 -0
  181. package/dist/policy/kinds.d.ts +9 -0
  182. package/dist/policy/kinds.d.ts.map +1 -0
  183. package/dist/policy/kinds.js +68 -0
  184. package/dist/policy/kinds.js.map +1 -0
  185. package/dist/policy/packs.d.ts +53 -0
  186. package/dist/policy/packs.d.ts.map +1 -0
  187. package/dist/policy/packs.js +336 -0
  188. package/dist/policy/packs.js.map +1 -0
  189. package/dist/policy/resolver.d.ts +87 -0
  190. package/dist/policy/resolver.d.ts.map +1 -0
  191. package/dist/policy/resolver.js +337 -0
  192. package/dist/policy/resolver.js.map +1 -0
  193. package/dist/policy/rules.d.ts +65 -0
  194. package/dist/policy/rules.d.ts.map +1 -0
  195. package/dist/policy/rules.js +194 -0
  196. package/dist/policy/rules.js.map +1 -0
  197. package/dist/protocol.d.ts +46 -0
  198. package/dist/protocol.d.ts.map +1 -0
  199. package/dist/protocol.js +86 -0
  200. package/dist/protocol.js.map +1 -0
  201. package/dist/render/adapters/chrome-pdf/cdp.d.ts +36 -0
  202. package/dist/render/adapters/chrome-pdf/cdp.d.ts.map +1 -0
  203. package/dist/render/adapters/chrome-pdf/cdp.js +291 -0
  204. package/dist/render/adapters/chrome-pdf/cdp.js.map +1 -0
  205. package/dist/render/adapters/chrome-pdf/index.d.ts +10 -0
  206. package/dist/render/adapters/chrome-pdf/index.d.ts.map +1 -0
  207. package/dist/render/adapters/chrome-pdf/index.js +139 -0
  208. package/dist/render/adapters/chrome-pdf/index.js.map +1 -0
  209. package/dist/render/adapters/chrome-pdf/network.d.ts +7 -0
  210. package/dist/render/adapters/chrome-pdf/network.d.ts.map +1 -0
  211. package/dist/render/adapters/chrome-pdf/network.js +33 -0
  212. package/dist/render/adapters/chrome-pdf/network.js.map +1 -0
  213. package/dist/render/adapters/html-preview/index.d.ts +8 -0
  214. package/dist/render/adapters/html-preview/index.d.ts.map +1 -0
  215. package/dist/render/adapters/html-preview/index.js +62 -0
  216. package/dist/render/adapters/html-preview/index.js.map +1 -0
  217. package/dist/render/adapters/test-json/index.d.ts +8 -0
  218. package/dist/render/adapters/test-json/index.d.ts.map +1 -0
  219. package/dist/render/adapters/test-json/index.js +62 -0
  220. package/dist/render/adapters/test-json/index.js.map +1 -0
  221. package/dist/render/adapters/typst-pdf/emitter.d.ts +21 -0
  222. package/dist/render/adapters/typst-pdf/emitter.d.ts.map +1 -0
  223. package/dist/render/adapters/typst-pdf/emitter.js +259 -0
  224. package/dist/render/adapters/typst-pdf/emitter.js.map +1 -0
  225. package/dist/render/adapters/typst-pdf/escape.d.ts +14 -0
  226. package/dist/render/adapters/typst-pdf/escape.d.ts.map +1 -0
  227. package/dist/render/adapters/typst-pdf/escape.js +56 -0
  228. package/dist/render/adapters/typst-pdf/escape.js.map +1 -0
  229. package/dist/render/adapters/typst-pdf/index.d.ts +9 -0
  230. package/dist/render/adapters/typst-pdf/index.d.ts.map +1 -0
  231. package/dist/render/adapters/typst-pdf/index.js +154 -0
  232. package/dist/render/adapters/typst-pdf/index.js.map +1 -0
  233. package/dist/render/adapters/typst-pdf/profile.d.ts +3 -0
  234. package/dist/render/adapters/typst-pdf/profile.d.ts.map +1 -0
  235. package/dist/render/adapters/typst-pdf/profile.js +55 -0
  236. package/dist/render/adapters/typst-pdf/profile.js.map +1 -0
  237. package/dist/render/adapters/typst-pdf/runner.d.ts +52 -0
  238. package/dist/render/adapters/typst-pdf/runner.d.ts.map +1 -0
  239. package/dist/render/adapters/typst-pdf/runner.js +209 -0
  240. package/dist/render/adapters/typst-pdf/runner.js.map +1 -0
  241. package/dist/render/adapters/typst-pdf/setup.d.ts +30 -0
  242. package/dist/render/adapters/typst-pdf/setup.d.ts.map +1 -0
  243. package/dist/render/adapters/typst-pdf/setup.js +183 -0
  244. package/dist/render/adapters/typst-pdf/setup.js.map +1 -0
  245. package/dist/render/adapters/typst-pdf/version.d.ts +8 -0
  246. package/dist/render/adapters/typst-pdf/version.d.ts.map +1 -0
  247. package/dist/render/adapters/typst-pdf/version.js +14 -0
  248. package/dist/render/adapters/typst-pdf/version.js.map +1 -0
  249. package/dist/render/assemble.d.ts +28 -0
  250. package/dist/render/assemble.d.ts.map +1 -0
  251. package/dist/render/assemble.js +309 -0
  252. package/dist/render/assemble.js.map +1 -0
  253. package/dist/render/assets.d.ts +27 -0
  254. package/dist/render/assets.d.ts.map +1 -0
  255. package/dist/render/assets.js +232 -0
  256. package/dist/render/assets.js.map +1 -0
  257. package/dist/render/build.d.ts +43 -0
  258. package/dist/render/build.d.ts.map +1 -0
  259. package/dist/render/build.js +187 -0
  260. package/dist/render/build.js.map +1 -0
  261. package/dist/render/charts.d.ts +83 -0
  262. package/dist/render/charts.d.ts.map +1 -0
  263. package/dist/render/charts.js +633 -0
  264. package/dist/render/charts.js.map +1 -0
  265. package/dist/render/default-registry.d.ts +7 -0
  266. package/dist/render/default-registry.d.ts.map +1 -0
  267. package/dist/render/default-registry.js +15 -0
  268. package/dist/render/default-registry.js.map +1 -0
  269. package/dist/render/diagram-theme.d.ts +7 -0
  270. package/dist/render/diagram-theme.d.ts.map +1 -0
  271. package/dist/render/diagram-theme.js +50 -0
  272. package/dist/render/diagram-theme.js.map +1 -0
  273. package/dist/render/dialect.d.ts +23 -0
  274. package/dist/render/dialect.d.ts.map +1 -0
  275. package/dist/render/dialect.js +188 -0
  276. package/dist/render/dialect.js.map +1 -0
  277. package/dist/render/html/citations.d.ts +70 -0
  278. package/dist/render/html/citations.d.ts.map +1 -0
  279. package/dist/render/html/citations.js +371 -0
  280. package/dist/render/html/citations.js.map +1 -0
  281. package/dist/render/html/css.d.ts +14 -0
  282. package/dist/render/html/css.d.ts.map +1 -0
  283. package/dist/render/html/css.js +113 -0
  284. package/dist/render/html/css.js.map +1 -0
  285. package/dist/render/html/emitter.d.ts +20 -0
  286. package/dist/render/html/emitter.d.ts.map +1 -0
  287. package/dist/render/html/emitter.js +652 -0
  288. package/dist/render/html/emitter.js.map +1 -0
  289. package/dist/render/html/escape.d.ts +11 -0
  290. package/dist/render/html/escape.d.ts.map +1 -0
  291. package/dist/render/html/escape.js +32 -0
  292. package/dist/render/html/escape.js.map +1 -0
  293. package/dist/render/html/katex.d.ts +9 -0
  294. package/dist/render/html/katex.d.ts.map +1 -0
  295. package/dist/render/html/katex.js +39 -0
  296. package/dist/render/html/katex.js.map +1 -0
  297. package/dist/render/html/stage.d.ts +12 -0
  298. package/dist/render/html/stage.d.ts.map +1 -0
  299. package/dist/render/html/stage.js +30 -0
  300. package/dist/render/html/stage.js.map +1 -0
  301. package/dist/render/index.d.ts +5 -0
  302. package/dist/render/index.d.ts.map +1 -0
  303. package/dist/render/index.js +5 -0
  304. package/dist/render/index.js.map +1 -0
  305. package/dist/render/math.d.ts +9 -0
  306. package/dist/render/math.d.ts.map +1 -0
  307. package/dist/render/math.js +60 -0
  308. package/dist/render/math.js.map +1 -0
  309. package/dist/render/model.d.ts +233 -0
  310. package/dist/render/model.d.ts.map +1 -0
  311. package/dist/render/model.js +2 -0
  312. package/dist/render/model.js.map +1 -0
  313. package/dist/render/numbering.d.ts +51 -0
  314. package/dist/render/numbering.d.ts.map +1 -0
  315. package/dist/render/numbering.js +155 -0
  316. package/dist/render/numbering.js.map +1 -0
  317. package/dist/render/output-name.d.ts +4 -0
  318. package/dist/render/output-name.d.ts.map +1 -0
  319. package/dist/render/output-name.js +11 -0
  320. package/dist/render/output-name.js.map +1 -0
  321. package/dist/render/palettes.d.ts +22 -0
  322. package/dist/render/palettes.d.ts.map +1 -0
  323. package/dist/render/palettes.js +46 -0
  324. package/dist/render/palettes.js.map +1 -0
  325. package/dist/render/parse.d.ts +15 -0
  326. package/dist/render/parse.d.ts.map +1 -0
  327. package/dist/render/parse.js +637 -0
  328. package/dist/render/parse.js.map +1 -0
  329. package/dist/render/port.d.ts +79 -0
  330. package/dist/render/port.d.ts.map +1 -0
  331. package/dist/render/port.js +2 -0
  332. package/dist/render/port.js.map +1 -0
  333. package/dist/render/registry.d.ts +11 -0
  334. package/dist/render/registry.d.ts.map +1 -0
  335. package/dist/render/registry.js +21 -0
  336. package/dist/render/registry.js.map +1 -0
  337. package/dist/render/text.d.ts +13 -0
  338. package/dist/render/text.d.ts.map +1 -0
  339. package/dist/render/text.js +65 -0
  340. package/dist/render/text.js.map +1 -0
  341. package/dist/render/walk.d.ts +13 -0
  342. package/dist/render/walk.d.ts.map +1 -0
  343. package/dist/render/walk.js +69 -0
  344. package/dist/render/walk.js.map +1 -0
  345. package/dist/research/bibtex.d.ts +12 -0
  346. package/dist/research/bibtex.d.ts.map +1 -0
  347. package/dist/research/bibtex.js +99 -0
  348. package/dist/research/bibtex.js.map +1 -0
  349. package/dist/research/client.d.ts +112 -0
  350. package/dist/research/client.d.ts.map +1 -0
  351. package/dist/research/client.js +661 -0
  352. package/dist/research/client.js.map +1 -0
  353. package/dist/research/dossier.d.ts +31 -0
  354. package/dist/research/dossier.d.ts.map +1 -0
  355. package/dist/research/dossier.js +54 -0
  356. package/dist/research/dossier.js.map +1 -0
  357. package/dist/research/flow.d.ts +31 -0
  358. package/dist/research/flow.d.ts.map +1 -0
  359. package/dist/research/flow.js +635 -0
  360. package/dist/research/flow.js.map +1 -0
  361. package/dist/research/library.d.ts +79 -0
  362. package/dist/research/library.d.ts.map +1 -0
  363. package/dist/research/library.js +319 -0
  364. package/dist/research/library.js.map +1 -0
  365. package/dist/research/verify.d.ts +80 -0
  366. package/dist/research/verify.d.ts.map +1 -0
  367. package/dist/research/verify.js +307 -0
  368. package/dist/research/verify.js.map +1 -0
  369. package/dist/resources.d.ts +15 -0
  370. package/dist/resources.d.ts.map +1 -0
  371. package/dist/resources.js +148 -0
  372. package/dist/resources.js.map +1 -0
  373. package/dist/review.d.ts +22 -0
  374. package/dist/review.d.ts.map +1 -0
  375. package/dist/review.js +355 -0
  376. package/dist/review.js.map +1 -0
  377. package/dist/schemas.d.ts +252 -0
  378. package/dist/schemas.d.ts.map +1 -0
  379. package/dist/schemas.js +1020 -0
  380. package/dist/schemas.js.map +1 -0
  381. package/dist/sections.d.ts +30 -0
  382. package/dist/sections.d.ts.map +1 -0
  383. package/dist/sections.js +62 -0
  384. package/dist/sections.js.map +1 -0
  385. package/dist/storage.d.ts +21 -0
  386. package/dist/storage.d.ts.map +1 -0
  387. package/dist/storage.js +296 -0
  388. package/dist/storage.js.map +1 -0
  389. package/dist/style-commands.d.ts +15 -0
  390. package/dist/style-commands.d.ts.map +1 -0
  391. package/dist/style-commands.js +54 -0
  392. package/dist/style-commands.js.map +1 -0
  393. package/dist/styles/csl.d.ts +58 -0
  394. package/dist/styles/csl.d.ts.map +1 -0
  395. package/dist/styles/csl.js +112 -0
  396. package/dist/styles/csl.js.map +1 -0
  397. package/dist/styles/discovery.d.ts +45 -0
  398. package/dist/styles/discovery.d.ts.map +1 -0
  399. package/dist/styles/discovery.js +99 -0
  400. package/dist/styles/discovery.js.map +1 -0
  401. package/dist/styles/golden.d.ts +52 -0
  402. package/dist/styles/golden.d.ts.map +1 -0
  403. package/dist/styles/golden.js +216 -0
  404. package/dist/styles/golden.js.map +1 -0
  405. package/dist/styles/profile.d.ts +126 -0
  406. package/dist/styles/profile.d.ts.map +1 -0
  407. package/dist/styles/profile.js +582 -0
  408. package/dist/styles/profile.js.map +1 -0
  409. package/dist/styles/xml.d.ts +22 -0
  410. package/dist/styles/xml.d.ts.map +1 -0
  411. package/dist/styles/xml.js +179 -0
  412. package/dist/styles/xml.js.map +1 -0
  413. package/dist/types.d.ts +285 -0
  414. package/dist/types.d.ts.map +1 -0
  415. package/dist/types.js +155 -0
  416. package/dist/types.js.map +1 -0
  417. package/dist/typst-pins.d.ts +16 -0
  418. package/dist/typst-pins.d.ts.map +1 -0
  419. package/dist/typst-pins.js +39 -0
  420. package/dist/typst-pins.js.map +1 -0
  421. package/dist/version.d.ts +2 -0
  422. package/dist/version.d.ts.map +1 -0
  423. package/dist/version.js +3 -0
  424. package/dist/version.js.map +1 -0
  425. package/dist/workflow.d.ts +49 -0
  426. package/dist/workflow.d.ts.map +1 -0
  427. package/dist/workflow.js +722 -0
  428. package/dist/workflow.js.map +1 -0
  429. package/dist/workspace.d.ts +12 -0
  430. package/dist/workspace.d.ts.map +1 -0
  431. package/dist/workspace.js +71 -0
  432. package/dist/workspace.js.map +1 -0
  433. package/package.json +70 -0
  434. package/policy-packs/countries/CO/academic-standards/ntc-1486-2022.yaml +188 -0
  435. package/policy-packs/countries/CO/copyright/decision-andina-351.yaml +61 -0
  436. package/policy-packs/countries/CO/copyright/ley-1915-2018.yaml +25 -0
  437. package/policy-packs/countries/CO/copyright/ley-23-1982.yaml +64 -0
  438. package/policy-packs/countries/CO/domains/health/resolucion-8430-1993.yaml +219 -0
  439. package/policy-packs/countries/CO/higher-education/ley-30-1992.yaml +61 -0
  440. package/policy-packs/countries/CO/manifest.yaml +42 -0
  441. package/policy-packs/countries/CO/official-domains.yaml +90 -0
  442. package/policy-packs/countries/CO/privacy/ley-1581-2012.yaml +197 -0
  443. package/policy-packs/countries/CO/research-integrity/minciencias-res-0314-2018.yaml +64 -0
  444. package/policy-packs/global/academic-integrity.yaml +45 -0
  445. package/policy-packs/global/academic-writing.yaml +70 -0
  446. package/policy-packs/global/evidence-quality.yaml +81 -0
  447. package/policy-packs/global/manifest.yaml +54 -0
  448. package/policy-packs/global/objective-verbs.yaml +245 -0
  449. package/policy-packs/global/reporting-guidelines.yaml +392 -0
  450. package/policy-packs/global/work-types.yaml +195 -0
  451. package/styles/LICENSE-CSL +375 -0
  452. package/styles/apa.csl +2283 -0
  453. package/styles/catalog.json +43 -0
  454. package/styles/fixtures/apa-7.expected.json +25 -0
  455. package/styles/fixtures/icontec-ntc1486-2022.expected.json +25 -0
  456. package/styles/fixtures/ieee.expected.json +25 -0
  457. package/styles/fixtures/references.jsonl +8 -0
  458. package/styles/icontec-ntc1486-2022.csl +388 -0
  459. package/styles/ieee.csl +519 -0
  460. package/templates/html/runtime.js +159 -0
  461. package/templates/html/thesis.css +98 -0
  462. package/templates/html/vendor/katex/LICENSE +21 -0
  463. package/templates/html/vendor/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  464. package/templates/html/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  465. package/templates/html/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  466. package/templates/html/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  467. package/templates/html/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  468. package/templates/html/vendor/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  469. package/templates/html/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  470. package/templates/html/vendor/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  471. package/templates/html/vendor/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  472. package/templates/html/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  473. package/templates/html/vendor/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  474. package/templates/html/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  475. package/templates/html/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  476. package/templates/html/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  477. package/templates/html/vendor/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  478. package/templates/html/vendor/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  479. package/templates/html/vendor/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  480. package/templates/html/vendor/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  481. package/templates/html/vendor/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  482. package/templates/html/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  483. package/templates/html/vendor/katex/katex.min.css +1 -0
  484. package/templates/html/vendor/katex/katex.min.js +1 -0
  485. package/templates/html/vendor/mermaid/LICENSE +21 -0
  486. package/templates/html/vendor/mermaid/mermaid.min.js +3587 -0
  487. package/templates/html/vendor/pagedjs/LICENSE +21 -0
  488. package/templates/html/vendor/pagedjs/paged.polyfill.min.js +4 -0
  489. package/templates/palettes.json +57 -0
  490. package/templates/profiles/apa-7.profile.yaml +15 -0
  491. package/templates/profiles/generic.profile.yaml +20 -0
  492. package/templates/profiles/icontec-ntc1486-2022.profile.yaml +36 -0
  493. package/templates/profiles/ieee.profile.yaml +14 -0
  494. package/templates/typst/i18n/en.yaml +31 -0
  495. package/templates/typst/i18n/es.yaml +31 -0
  496. package/templates/typst/i18n/pt.yaml +31 -0
  497. package/templates/typst/thesis.typ +276 -0
  498. package/typst-packages/preview/merman/0.3.0/LICENSE +231 -0
  499. package/typst-packages/preview/merman/0.3.0/README.md +388 -0
  500. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/cose-base-v1/LICENSE +21 -0
  501. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/cose-base-v2/LICENSE +21 -0
  502. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/cytoscape/LICENSE +19 -0
  503. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/cytoscape-cose-bilkent/LICENSE +21 -0
  504. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/cytoscape-fcose/LICENSE +19 -0
  505. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/d3-shape/LICENSE +13 -0
  506. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/dagre/LICENSE +19 -0
  507. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/dompurify/LICENSE +202 -0
  508. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/eclipse-elk/LICENSE.md +264 -0
  509. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/elkjs/LICENSE.md +264 -0
  510. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/fmin/LICENSE +27 -0
  511. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/graphlib/LICENSE +19 -0
  512. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/layout-base-v1/LICENSE +21 -0
  513. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/layout-base-v2/LICENSE +21 -0
  514. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/mermaid/LICENSE +21 -0
  515. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/rough-rs/LICENSE +21 -0
  516. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/roughjs/LICENSE +21 -0
  517. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/sanitize-url/LICENSE +21 -0
  518. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/venn-js/LICENSE +22 -0
  519. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/wasm-minimal-protocol/LICENSE +24 -0
  520. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_LICENSES/zenuml-core/LICENSE +21 -0
  521. package/typst-packages/preview/merman/0.3.0/THIRD_PARTY_NOTICES.md +265 -0
  522. package/typst-packages/preview/merman/0.3.0/lib.typ +1 -0
  523. package/typst-packages/preview/merman/0.3.0/merman_typst_plugin.wasm +0 -0
  524. package/typst-packages/preview/merman/0.3.0/src/capabilities.typ +5 -0
  525. package/typst-packages/preview/merman/0.3.0/src/context.typ +1 -0
  526. package/typst-packages/preview/merman/0.3.0/src/errors.typ +33 -0
  527. package/typst-packages/preview/merman/0.3.0/src/exports.typ +5 -0
  528. package/typst-packages/preview/merman/0.3.0/src/figure.typ +143 -0
  529. package/typst-packages/preview/merman/0.3.0/src/image.typ +50 -0
  530. package/typst-packages/preview/merman/0.3.0/src/options.typ +566 -0
  531. package/typst-packages/preview/merman/0.3.0/src/plugin.typ +1 -0
  532. package/typst-packages/preview/merman/0.3.0/src/raw.typ +22 -0
  533. package/typst-packages/preview/merman/0.3.0/src/render.typ +137 -0
  534. package/typst-packages/preview/merman/0.3.0/src/source.typ +7 -0
  535. package/typst-packages/preview/merman/0.3.0/src/units.typ +51 -0
  536. package/typst-packages/preview/merman/0.3.0/typst.toml +12 -0
  537. package/typst-packages/preview/mitex/0.2.7/CHANGELOG.md +69 -0
  538. package/typst-packages/preview/mitex/0.2.7/LICENSE +176 -0
  539. package/typst-packages/preview/mitex/0.2.7/README.md +154 -0
  540. package/typst-packages/preview/mitex/0.2.7/lib.typ +1 -0
  541. package/typst-packages/preview/mitex/0.2.7/mitex.typ +45 -0
  542. package/typst-packages/preview/mitex/0.2.7/mitex.wasm +0 -0
  543. package/typst-packages/preview/mitex/0.2.7/specs/README.md +250 -0
  544. package/typst-packages/preview/mitex/0.2.7/specs/latex/standard.typ +1187 -0
  545. package/typst-packages/preview/mitex/0.2.7/specs/mod.typ +12 -0
  546. package/typst-packages/preview/mitex/0.2.7/specs/prelude.typ +230 -0
  547. package/typst-packages/preview/mitex/0.2.7/typst.toml +12 -0
@@ -0,0 +1,661 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { stripControl } from "../schemas.js";
5
+ import { atomicWrite } from "../storage.js";
6
+ import { VERSION } from "../version.js";
7
+ /** Fixed scholarly origins (spec 8.2). Nothing else is ever contacted by this client. */
8
+ export const origins = {
9
+ openalex: "https://api.openalex.org",
10
+ crossref: "https://api.crossref.org",
11
+ arxiv: "https://export.arxiv.org",
12
+ };
13
+ export const limits = {
14
+ timeoutMs: 8000,
15
+ responseBytes: 1024 * 1024,
16
+ arxivSpacingMs: 3000,
17
+ };
18
+ export const realClock = {
19
+ now: () => Date.now(),
20
+ sleep: (ms, signal) => new Promise((resolve, reject) => {
21
+ const timer = setTimeout(resolve, ms);
22
+ signal?.addEventListener("abort", () => {
23
+ clearTimeout(timer);
24
+ reject(new Error("source unavailable"));
25
+ }, { once: true });
26
+ }),
27
+ };
28
+ // ---------------------------------------------------------------------------------------------
29
+ // Sanitizing
30
+ // ---------------------------------------------------------------------------------------------
31
+ /** Remove control characters and markup noise, collapse whitespace and cap the length. */
32
+ export function clean(value, max = 300) {
33
+ if (typeof value !== "string")
34
+ return null;
35
+ const text = stripControl(decodeEntities(value.replace(/<[^>]*>/g, " ")))
36
+ .replace(/\s+/g, " ")
37
+ .trim()
38
+ .slice(0, max);
39
+ return text || null;
40
+ }
41
+ const namedEntities = {
42
+ amp: "&",
43
+ lt: "<",
44
+ gt: ">",
45
+ quot: '"',
46
+ apos: "'",
47
+ nbsp: " ",
48
+ };
49
+ function decodeEntities(value) {
50
+ return value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (whole, body) => {
51
+ if (body.startsWith("#")) {
52
+ const code = body[1] === "x" || body[1] === "X"
53
+ ? Number.parseInt(body.slice(2), 16)
54
+ : Number(body.slice(1));
55
+ return Number.isInteger(code) && code > 31 && code < 0x110000
56
+ ? String.fromCodePoint(code)
57
+ : "";
58
+ }
59
+ return namedEntities[body] ?? whole;
60
+ });
61
+ }
62
+ function safeUrl(value) {
63
+ if (typeof value !== "string")
64
+ return null;
65
+ try {
66
+ const url = new URL(value.trim());
67
+ if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username || url.password) {
68
+ return null;
69
+ }
70
+ const text = url.toString();
71
+ return text.length <= 500 ? text : null;
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
78
+ const asArray = (value) => (Array.isArray(value) ? value : []);
79
+ const firstString = (value) => (Array.isArray(value) ? value[0] : value);
80
+ function year(value) {
81
+ const number = typeof value === "number" ? value : Number(value);
82
+ return Number.isInteger(number) && number >= 1000 && number <= 2200 ? number : null;
83
+ }
84
+ function bareOrcid(value) {
85
+ if (typeof value !== "string")
86
+ return null;
87
+ const match = /(\d{4}-\d{4}-\d{4}-\d{3}[\dX])/.exec(value);
88
+ return match ? match[1] : null;
89
+ }
90
+ const maxAuthors = 50;
91
+ function bareDoi(value) {
92
+ if (typeof value !== "string")
93
+ return null;
94
+ const doi = value
95
+ .trim()
96
+ .replace(/^https?:\/\/(?:dx\.)?doi\.org\//i, "")
97
+ .replace(/^doi:\s*/i, "")
98
+ .toLowerCase();
99
+ return /^10\.\d{4,9}\/\S{1,200}$/.test(doi) ? doi : null;
100
+ }
101
+ // ---------------------------------------------------------------------------------------------
102
+ // Identifiers and input
103
+ // ---------------------------------------------------------------------------------------------
104
+ export function parseIdentifier(raw) {
105
+ if (typeof raw !== "string")
106
+ throw new Error("invalid identifier");
107
+ const text = raw.trim();
108
+ if (text.length < 1 || text.length > 2048)
109
+ throw new Error("invalid identifier");
110
+ let value = text;
111
+ try {
112
+ value = decodeURIComponent(text);
113
+ }
114
+ catch {
115
+ // keep the raw text
116
+ }
117
+ value = value
118
+ .replace(/^doi:\s*/i, "")
119
+ .replace(/^https?:\/\/(?:dx\.)?doi\.org\//i, "")
120
+ .trim();
121
+ if (/^10\.\d{4,9}\/[^\s]{1,200}$/i.test(value))
122
+ return { kind: "doi", value: value.toLowerCase() };
123
+ const arxivUrl = /^https?:\/\/arxiv\.org\/(?:abs|pdf)\/(.+?)(?:\.pdf)?$/i.exec(value);
124
+ const arxiv = /^(?:arxiv:)?(\d{4}\.\d{4,5}|[a-z-]+(?:\.[a-z-]+)?\/\d{7})(v\d+)?$/i.exec(arxivUrl ? arxivUrl[1] : value);
125
+ if (arxiv)
126
+ return { kind: "arxiv", value: arxiv[1].toLowerCase() };
127
+ const openalex = /^(?:https?:\/\/openalex\.org\/)?(W\d{1,12})$/i.exec(value);
128
+ if (openalex)
129
+ return { kind: "openalex", value: openalex[1].toUpperCase() };
130
+ const url = safeUrl(value);
131
+ if (url) {
132
+ const parsed = new URL(url);
133
+ parsed.hash = "";
134
+ return { kind: "url", value: parsed.toString() };
135
+ }
136
+ throw new Error("invalid identifier");
137
+ }
138
+ const yearBounds = { min: 1600, max: new Date().getUTCFullYear() + 1 };
139
+ export function parseSearchInput(input) {
140
+ if (!isRecord(input))
141
+ throw new Error("invalid input");
142
+ const allowed = ["query", "source", "limit", "fromYear", "toYear", "language"];
143
+ if (Object.keys(input).some((key) => !allowed.includes(key)))
144
+ throw new Error("invalid input");
145
+ const query = typeof input.query === "string" ? input.query.trim() : "";
146
+ if (query.length < 1 || query.length > 512)
147
+ throw new Error("invalid input");
148
+ if (input.source !== "openalex" && input.source !== "crossref" && input.source !== "arxiv") {
149
+ throw new Error("invalid input");
150
+ }
151
+ let limit = 10;
152
+ if (input.limit !== undefined) {
153
+ if (!Number.isInteger(input.limit) ||
154
+ input.limit < 1 ||
155
+ input.limit > 25) {
156
+ throw new Error("invalid input");
157
+ }
158
+ limit = input.limit;
159
+ }
160
+ const result = { query: stripControl(query), source: input.source, limit };
161
+ for (const key of ["fromYear", "toYear"]) {
162
+ const value = input[key];
163
+ if (value === undefined)
164
+ continue;
165
+ if (!Number.isInteger(value) ||
166
+ value < yearBounds.min ||
167
+ value > yearBounds.max) {
168
+ throw new Error("invalid input");
169
+ }
170
+ result[key] = value;
171
+ }
172
+ if (result.fromYear && result.toYear && result.fromYear > result.toYear)
173
+ throw new Error("invalid input");
174
+ if (input.language !== undefined) {
175
+ if (typeof input.language !== "string" || !/^[a-z]{2,3}$/i.test(input.language)) {
176
+ throw new Error("invalid input");
177
+ }
178
+ result.language = input.language.toLowerCase();
179
+ }
180
+ return result;
181
+ }
182
+ // ---------------------------------------------------------------------------------------------
183
+ // Normalizers (pure; exercised by recorded fixtures)
184
+ // ---------------------------------------------------------------------------------------------
185
+ const crossrefTypes = {
186
+ "journal-article": "journal_article",
187
+ "proceedings-article": "conference_paper",
188
+ book: "book",
189
+ monograph: "book",
190
+ "edited-book": "book",
191
+ "reference-book": "book",
192
+ "book-chapter": "chapter",
193
+ "book-section": "chapter",
194
+ "reference-entry": "chapter",
195
+ dissertation: "thesis",
196
+ report: "report",
197
+ "report-component": "report",
198
+ standard: "standard",
199
+ dataset: "dataset",
200
+ "posted-content": "preprint",
201
+ };
202
+ const openalexTypes = {
203
+ article: "journal_article",
204
+ book: "book",
205
+ "book-chapter": "chapter",
206
+ dissertation: "thesis",
207
+ dataset: "dataset",
208
+ report: "report",
209
+ standard: "standard",
210
+ preprint: "preprint",
211
+ };
212
+ function crossrefRetracted(item) {
213
+ const isRetraction = (entry) => isRecord(entry) && typeof entry.type === "string" && /retract/i.test(entry.type);
214
+ if (asArray(item["update-to"]).some(isRetraction))
215
+ return true;
216
+ if (asArray(item["updated-by"]).some(isRetraction))
217
+ return true;
218
+ const relation = item.relation;
219
+ return isRecord(relation) && Object.keys(relation).some((key) => /retract/i.test(key));
220
+ }
221
+ export function normalizeCrossref(item) {
222
+ if (!isRecord(item))
223
+ return undefined;
224
+ const doi = bareDoi(item.DOI);
225
+ const title = clean(firstString(item.title), 500);
226
+ if (!title)
227
+ return undefined;
228
+ const issued = firstDateYear(item.issued) ??
229
+ firstDateYear(item["published-print"]) ??
230
+ firstDateYear(item["published-online"]);
231
+ const authors = asArray(item.author)
232
+ .filter(isRecord)
233
+ .slice(0, maxAuthors)
234
+ .map((author) => {
235
+ const family = clean(author.family, 120) ?? clean(author.name, 200);
236
+ return family
237
+ ? { family, given: clean(author.given, 120), orcid: bareOrcid(author.ORCID) }
238
+ : undefined;
239
+ })
240
+ .filter((author) => author !== undefined);
241
+ const license = asArray(item.license).find(isRecord);
242
+ const type = crossrefTypes[typeof item.type === "string" ? item.type : ""] ?? "other";
243
+ const isbn = asArray(item.ISBN)[0];
244
+ const record = {
245
+ id: doi ?? title,
246
+ doi,
247
+ title,
248
+ authors,
249
+ year: issued,
250
+ containerTitle: clean(firstString(item["container-title"]), 300),
251
+ type,
252
+ publisher: clean(item.publisher, 200),
253
+ ...(clean(item["publisher-location"], 120)
254
+ ? { placeOfPublication: clean(item["publisher-location"], 120) }
255
+ : {}),
256
+ issn: clean(asArray(item.ISSN)[0], 20),
257
+ isbn: clean(isbn, 20),
258
+ volume: clean(item.volume, 40),
259
+ issue: clean(item.issue, 40),
260
+ pages: clean(item.page, 40),
261
+ language: clean(item.language, 12),
262
+ url: safeUrl(item.URL) ?? (doi ? `https://doi.org/${doi}` : null),
263
+ oaUrl: null,
264
+ license: license ? safeUrl(license.URL) : null,
265
+ abstract: clean(item.abstract, 2000),
266
+ source: "crossref",
267
+ };
268
+ return { record, retracted: crossrefRetracted(item) };
269
+ }
270
+ function firstDateYear(value) {
271
+ if (!isRecord(value))
272
+ return null;
273
+ const parts = asArray(value["date-parts"])[0];
274
+ return year(asArray(parts)[0]);
275
+ }
276
+ function invertedAbstract(value) {
277
+ if (!isRecord(value))
278
+ return null;
279
+ const words = [];
280
+ for (const [word, positions] of Object.entries(value)) {
281
+ for (const position of asArray(positions)) {
282
+ if (Number.isInteger(position) && position >= 0 && position < 20000) {
283
+ words.push([position, word]);
284
+ }
285
+ }
286
+ }
287
+ words.sort((a, b) => a[0] - b[0]);
288
+ return clean(words.map(([, word]) => word).join(" "), 2000);
289
+ }
290
+ export function normalizeOpenAlex(item) {
291
+ if (!isRecord(item))
292
+ return undefined;
293
+ const title = clean(item.display_name ?? item.title, 500);
294
+ if (!title)
295
+ return undefined;
296
+ const id = typeof item.id === "string" ? /(W\d{1,12})$/.exec(item.id)?.[1] : undefined;
297
+ const doi = bareDoi(item.doi);
298
+ const location = isRecord(item.primary_location) ? item.primary_location : {};
299
+ const source = isRecord(location.source) ? location.source : {};
300
+ const access = isRecord(item.open_access) ? item.open_access : {};
301
+ const biblio = isRecord(item.biblio) ? item.biblio : {};
302
+ const authors = asArray(item.authorships)
303
+ .filter(isRecord)
304
+ .slice(0, maxAuthors)
305
+ .map((entry) => {
306
+ const author = isRecord(entry.author) ? entry.author : {};
307
+ const name = clean(author.display_name, 200);
308
+ if (!name)
309
+ return undefined;
310
+ const parts = name.split(" ");
311
+ const family = parts.length > 1 ? parts.pop() : name;
312
+ return {
313
+ family,
314
+ given: parts.length > 0 ? parts.join(" ") : null,
315
+ orcid: bareOrcid(author.orcid),
316
+ };
317
+ })
318
+ .filter((author) => author !== undefined);
319
+ let type = openalexTypes[typeof item.type === "string" ? item.type : ""] ?? "other";
320
+ if (type === "journal_article" && source.type === "conference")
321
+ type = "conference_paper";
322
+ if (type === "journal_article" && source.type === "repository")
323
+ type = "preprint";
324
+ const first = clean(biblio.first_page, 20);
325
+ const last = clean(biblio.last_page, 20);
326
+ const record = {
327
+ id: id ?? doi ?? title,
328
+ doi,
329
+ title,
330
+ authors,
331
+ year: year(item.publication_year),
332
+ containerTitle: clean(source.display_name, 300),
333
+ type,
334
+ publisher: clean(source.host_organization_name, 200),
335
+ issn: clean(source.issn_l, 20),
336
+ isbn: null,
337
+ volume: clean(biblio.volume, 40),
338
+ issue: clean(biblio.issue, 40),
339
+ pages: first && last ? `${first}-${last}` : first,
340
+ language: clean(item.language, 12),
341
+ url: safeUrl(location.landing_page_url) ?? (doi ? `https://doi.org/${doi}` : null),
342
+ oaUrl: safeUrl(access.oa_url),
343
+ license: clean(location.license, 60),
344
+ abstract: invertedAbstract(item.abstract_inverted_index),
345
+ source: "openalex",
346
+ };
347
+ return { record, retracted: item.is_retracted === true };
348
+ }
349
+ function xmlText(block, tag) {
350
+ const match = new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)</${tag}>`).exec(block);
351
+ return match ? clean(match[1], 2000) : null;
352
+ }
353
+ export function normalizeArxiv(xml) {
354
+ const records = [];
355
+ for (const match of xml.matchAll(/<entry>([\s\S]*?)<\/entry>/g)) {
356
+ const block = match[1];
357
+ const idUrl = xmlText(block, "id");
358
+ const id = idUrl
359
+ ? /arxiv\.org\/abs\/(.+?)(?:v\d+)?$/i.exec(idUrl)?.[1]?.toLowerCase()
360
+ : undefined;
361
+ const title = clean(xmlText(block, "title"), 500);
362
+ if (!id || !title)
363
+ continue;
364
+ const authors = [...block.matchAll(/<author>\s*<name>([\s\S]*?)<\/name>/g)]
365
+ .slice(0, maxAuthors)
366
+ .map((author) => clean(author[1], 200))
367
+ .filter((name) => name !== null)
368
+ .map((name) => {
369
+ const parts = name.split(" ");
370
+ const family = parts.length > 1 ? parts.pop() : name;
371
+ return { family, given: parts.length > 0 ? parts.join(" ") : null, orcid: null };
372
+ });
373
+ const published = xmlText(block, "published");
374
+ records.push({
375
+ id,
376
+ doi: bareDoi(xmlText(block, "arxiv:doi")),
377
+ title,
378
+ authors,
379
+ year: published ? year(published.slice(0, 4)) : null,
380
+ containerTitle: clean(xmlText(block, "arxiv:journal_ref"), 300),
381
+ type: "preprint",
382
+ publisher: "arXiv",
383
+ issn: null,
384
+ isbn: null,
385
+ volume: null,
386
+ issue: null,
387
+ pages: null,
388
+ language: "en",
389
+ url: `https://arxiv.org/abs/${id}`,
390
+ oaUrl: `https://arxiv.org/pdf/${id}`,
391
+ license: null,
392
+ abstract: xmlText(block, "summary"),
393
+ source: "arxiv",
394
+ });
395
+ }
396
+ return records;
397
+ }
398
+ // ---------------------------------------------------------------------------------------------
399
+ // Client
400
+ // ---------------------------------------------------------------------------------------------
401
+ const openalexSelect = [
402
+ "id",
403
+ "doi",
404
+ "display_name",
405
+ "publication_year",
406
+ "authorships",
407
+ "primary_location",
408
+ "type",
409
+ "language",
410
+ "open_access",
411
+ "biblio",
412
+ "is_retracted",
413
+ "abstract_inverted_index",
414
+ ].join(",");
415
+ const contactPattern = /^[^\s@<>"']{1,64}@[^\s@<>"']{1,190}$/;
416
+ /** Resolved records are cached for 24 hours (spec 15). */
417
+ export const resolveCacheTtlMs = 24 * 60 * 60 * 1000;
418
+ export class ScholarClient {
419
+ cacheDir;
420
+ fetcher;
421
+ clock;
422
+ env;
423
+ timeoutMs;
424
+ crossrefTail = Promise.resolve();
425
+ arxivNext = 0;
426
+ constructor(options = {}) {
427
+ this.fetcher = options.fetch ?? ((input, init) => fetch(input, init));
428
+ this.clock = options.clock ?? realClock;
429
+ this.env = options.env ?? process.env;
430
+ this.timeoutMs = options.timeoutMs ?? limits.timeoutMs;
431
+ }
432
+ /** Cache resolved records under `dir` (for example `<thesis>/build/cache/scholar`). */
433
+ useCache(dir) {
434
+ this.cacheDir = dir;
435
+ }
436
+ cacheFile(identifier) {
437
+ if (!this.cacheDir)
438
+ return undefined;
439
+ const key = createHash("sha256").update(`${identifier.kind}:${identifier.value}`).digest("hex");
440
+ return join(this.cacheDir, `${key}.json`);
441
+ }
442
+ async readCache(identifier) {
443
+ const file = this.cacheFile(identifier);
444
+ if (!file)
445
+ return undefined;
446
+ try {
447
+ const entry = JSON.parse(await readFile(file, "utf8"));
448
+ if (typeof entry.at === "number" &&
449
+ this.clock.now() - entry.at < resolveCacheTtlMs &&
450
+ entry.at <= this.clock.now() &&
451
+ entry.resolved?.record &&
452
+ typeof entry.resolved.retracted === "boolean") {
453
+ return entry.resolved;
454
+ }
455
+ }
456
+ catch {
457
+ // A missing or damaged cache entry is a miss.
458
+ }
459
+ return undefined;
460
+ }
461
+ async writeCache(identifier, resolved) {
462
+ const file = this.cacheFile(identifier);
463
+ if (!file)
464
+ return;
465
+ try {
466
+ await atomicWrite(file, `${JSON.stringify({ at: this.clock.now(), resolved })}\n`);
467
+ }
468
+ catch {
469
+ // The cache is an optimization; a read-only workspace must not fail the lookup.
470
+ }
471
+ }
472
+ /** Optional polite-pool contact; read per call from the environment, never stored or logged. */
473
+ contact() {
474
+ const value = this.env.ALISIO_THESIS_CONTACT_EMAIL?.trim();
475
+ return value && contactPattern.test(value) ? value : undefined;
476
+ }
477
+ async search(input, signal) {
478
+ const records = (await this.searchSource(input, signal)).slice(0, input.limit);
479
+ return records.filter((record) => (input.fromYear === undefined || record.year === null || record.year >= input.fromYear) &&
480
+ (input.toYear === undefined || record.year === null || record.year <= input.toYear));
481
+ }
482
+ async searchSource(input, signal) {
483
+ const query = new URLSearchParams();
484
+ if (input.source === "openalex") {
485
+ query.set("search", input.query);
486
+ query.set("per-page", String(input.limit));
487
+ query.set("select", openalexSelect);
488
+ const filters = [];
489
+ if (input.fromYear)
490
+ filters.push(`from_publication_date:${input.fromYear}-01-01`);
491
+ if (input.toYear)
492
+ filters.push(`to_publication_date:${input.toYear}-12-31`);
493
+ if (input.language)
494
+ filters.push(`language:${input.language}`);
495
+ if (filters.length)
496
+ query.set("filter", filters.join(","));
497
+ const contact = this.contact();
498
+ if (contact)
499
+ query.set("mailto", contact);
500
+ const body = await this.request("openalex", `/works?${query}`, signal);
501
+ return asArray(parseJson(body).results)
502
+ .map(normalizeOpenAlex)
503
+ .filter((entry) => entry !== undefined)
504
+ .map((entry) => entry.record);
505
+ }
506
+ if (input.source === "crossref") {
507
+ query.set("query.bibliographic", input.query);
508
+ query.set("rows", String(input.limit));
509
+ const filters = [];
510
+ if (input.fromYear)
511
+ filters.push(`from-pub-date:${input.fromYear}`);
512
+ if (input.toYear)
513
+ filters.push(`until-pub-date:${input.toYear}`);
514
+ if (filters.length)
515
+ query.set("filter", filters.join(","));
516
+ const message = parseJson(await this.request("crossref", `/works?${query}`, signal)).message;
517
+ return asArray(isRecord(message) ? message.items : undefined)
518
+ .map(normalizeCrossref)
519
+ .filter((entry) => entry !== undefined)
520
+ .map((entry) => entry.record);
521
+ }
522
+ query.set("search_query", `all:${input.query.replace(/["\\]/g, " ")}`);
523
+ query.set("start", "0");
524
+ query.set("max_results", String(input.limit));
525
+ query.set("sortBy", "relevance");
526
+ return normalizeArxiv(await this.request("arxiv", `/api/query?${query}`, signal));
527
+ }
528
+ async resolve(identifier, signal) {
529
+ if (identifier.kind === "url")
530
+ return undefined;
531
+ const cached = await this.readCache(identifier);
532
+ if (cached)
533
+ return cached;
534
+ const resolved = await this.resolveRemote(identifier, signal);
535
+ if (resolved)
536
+ await this.writeCache(identifier, resolved);
537
+ return resolved;
538
+ }
539
+ async resolveRemote(identifier, signal) {
540
+ if (identifier.kind === "arxiv") {
541
+ const query = new URLSearchParams({ id_list: identifier.value });
542
+ const [record] = normalizeArxiv(await this.request("arxiv", `/api/query?${query}`, signal));
543
+ return record ? { record, retracted: false } : undefined;
544
+ }
545
+ if (identifier.kind === "openalex") {
546
+ return this.openalexWork(identifier.value, signal);
547
+ }
548
+ // DOI: Crossref first, OpenAlex when Crossref does not know it.
549
+ const path = identifier.value.split("/").map(encodeURIComponent).join("/");
550
+ const contact = this.contact();
551
+ try {
552
+ const body = parseJson(await this.request("crossref", `/works/${path}${contact ? `?mailto=${encodeURIComponent(contact)}` : ""}`, signal));
553
+ return normalizeCrossref(body.message);
554
+ }
555
+ catch (error) {
556
+ if (error.message !== "record not found")
557
+ throw error;
558
+ }
559
+ return this.openalexWork(`doi:https://doi.org/${identifier.value}`, signal);
560
+ }
561
+ async openalexWork(id, signal) {
562
+ const query = new URLSearchParams({ select: openalexSelect });
563
+ const contact = this.contact();
564
+ if (contact)
565
+ query.set("mailto", contact);
566
+ try {
567
+ return normalizeOpenAlex(parseJson(await this.request("openalex", `/works/${encodeURI(id)}?${query}`, signal)));
568
+ }
569
+ catch (error) {
570
+ if (error.message === "record not found")
571
+ return undefined;
572
+ throw error;
573
+ }
574
+ }
575
+ // -------------------------------------------------------------------------------------------
576
+ request(source, path, outer) {
577
+ if (source === "crossref") {
578
+ // Single flight: at most one Crossref request is in progress; callers queue behind it.
579
+ const run = this.crossrefTail.then(() => this.send(source, path, outer), () => this.send(source, path, outer));
580
+ this.crossrefTail = run.catch(() => undefined);
581
+ return run;
582
+ }
583
+ return this.send(source, path, outer);
584
+ }
585
+ async send(source, path, outer) {
586
+ outer?.throwIfAborted();
587
+ if (source === "arxiv") {
588
+ const slot = Math.max(this.clock.now(), this.arxivNext);
589
+ this.arxivNext = slot + limits.arxivSpacingMs;
590
+ const wait = slot - this.clock.now();
591
+ if (wait > 0)
592
+ await this.clock.sleep(wait, outer);
593
+ }
594
+ const signal = outer
595
+ ? AbortSignal.any([outer, AbortSignal.timeout(this.timeoutMs)])
596
+ : AbortSignal.timeout(this.timeoutMs);
597
+ const contact = this.contact();
598
+ let response;
599
+ try {
600
+ response = await this.fetcher(`${origins[source]}${path}`, {
601
+ method: "GET",
602
+ redirect: "manual",
603
+ headers: {
604
+ accept: source === "arxiv" ? "application/atom+xml" : "application/json",
605
+ "user-agent": `alisio-plugin-thesis/${VERSION}${source === "crossref" && contact ? ` (mailto:${contact})` : ""}`,
606
+ },
607
+ signal,
608
+ });
609
+ }
610
+ catch {
611
+ throw new Error("source unavailable");
612
+ }
613
+ if (response.status >= 300 && response.status < 400)
614
+ throw new Error("source returned redirect");
615
+ if (response.status === 404)
616
+ throw new Error("record not found");
617
+ if (response.status === 429)
618
+ throw new Error("source rate limited");
619
+ if (!response.ok)
620
+ throw new Error("source unavailable");
621
+ if (response.redirected)
622
+ throw new Error("source returned redirect");
623
+ return readCapped(response, signal);
624
+ }
625
+ }
626
+ async function readCapped(response, signal) {
627
+ const reader = response.body?.getReader();
628
+ if (!reader)
629
+ return "";
630
+ const chunks = [];
631
+ let bytes = 0;
632
+ try {
633
+ for (;;) {
634
+ signal.throwIfAborted();
635
+ const next = await reader.read();
636
+ if (next.done)
637
+ break;
638
+ bytes += next.value.byteLength;
639
+ if (bytes > limits.responseBytes) {
640
+ await reader.cancel().catch(() => undefined);
641
+ throw new Error("response exceeded limit");
642
+ }
643
+ chunks.push(next.value);
644
+ }
645
+ }
646
+ catch (error) {
647
+ if (error.message === "response exceeded limit")
648
+ throw error;
649
+ throw new Error("source unavailable");
650
+ }
651
+ return new TextDecoder().decode(Buffer.concat(chunks));
652
+ }
653
+ function parseJson(text) {
654
+ try {
655
+ return JSON.parse(text);
656
+ }
657
+ catch {
658
+ throw new Error("source unavailable");
659
+ }
660
+ }
661
+ //# sourceMappingURL=client.js.map