@herbertgao/pi-extensions 2026.11.11 → 2026.11.13

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 (262) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +13 -11
  3. package/THIRD_PARTY_NOTICES.md +3 -3
  4. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +10 -0
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -4
  6. package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -4
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/core.ts +22 -15
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/index.ts +22 -8
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +0 -29
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +5 -2
  11. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +60 -39
  12. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +3 -2
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/codemode.ts +0 -40
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-parse.ts +4 -1
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +21 -3
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/format.ts +15 -0
  17. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  18. package/node_modules/@herbertgao/pi-impeccable/CHANGELOG.md +6 -0
  19. package/node_modules/@herbertgao/pi-impeccable/README.md +2 -2
  20. package/node_modules/@herbertgao/pi-impeccable/package.json +4 -4
  21. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/SKILL.md +2 -2
  22. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/adapt.md +1 -1
  23. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/animate.md +17 -0
  24. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/critique-rubric.md +496 -0
  25. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/critique.md +12 -504
  26. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/degraded/motion-reviewer.md +29 -0
  27. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/hooks.md +3 -3
  28. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work-comp.md +24 -0
  29. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work-world.md +20 -0
  30. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work.md +5 -34
  31. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/typeset.md +6 -0
  32. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/VERSION +1 -1
  33. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/engine-checksums.txt +5 -5
  34. package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/live-browser.js +17 -18
  35. package/node_modules/@herbertgao/pi-inline-skill-commands/LICENSE +21 -0
  36. package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +33 -0
  37. package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +53 -0
  38. package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +213 -0
  39. package/node_modules/pi-antigravity/README.md +58 -9
  40. package/node_modules/pi-antigravity/docs/reader-guarantees.md +35 -0
  41. package/node_modules/pi-antigravity/package.json +15 -6
  42. package/node_modules/pi-antigravity/src/client/client.ts +63 -14
  43. package/node_modules/pi-antigravity/src/client/enterprise.ts +150 -0
  44. package/node_modules/pi-antigravity/src/client/index.ts +1 -0
  45. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +7 -0
  46. package/node_modules/pi-antigravity/src/features/generate-image.ts +56 -2
  47. package/node_modules/pi-antigravity/src/features/read-url-content.ts +124 -0
  48. package/node_modules/pi-antigravity/src/image/image.ts +16 -2
  49. package/node_modules/pi-antigravity/src/index.ts +145 -2
  50. package/node_modules/pi-antigravity/src/models/discovery.ts +3 -4
  51. package/node_modules/pi-antigravity/src/models/grouping.ts +39 -15
  52. package/node_modules/pi-antigravity/src/models/models.ts +126 -14
  53. package/node_modules/pi-antigravity/src/stream/stream.ts +189 -30
  54. package/node_modules/pi-antigravity/src/types/types.ts +30 -1
  55. package/node_modules/pi-antigravity/src/usage/usage.ts +58 -0
  56. package/node_modules/pi-antigravity/src/utils/address.ts +180 -0
  57. package/node_modules/pi-antigravity/src/utils/credits.ts +149 -0
  58. package/node_modules/pi-antigravity/src/utils/html.ts +31 -0
  59. package/node_modules/pi-antigravity/src/utils/index.ts +2 -0
  60. package/node_modules/pi-antigravity/src/utils/security.ts +172 -13
  61. package/node_modules/pi-antigravity/src/utils/text.ts +66 -0
  62. package/node_modules/pi-antigravity/src/utils/util.ts +5 -4
  63. package/node_modules/pi-antigravity/src/web-fetch/document.ts +83 -0
  64. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +24 -0
  65. package/node_modules/pi-antigravity/src/web-fetch/header.ts +97 -0
  66. package/node_modules/pi-antigravity/src/web-fetch/index.ts +3 -0
  67. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +328 -0
  68. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +4 -0
  69. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +744 -0
  70. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +164 -0
  71. package/node_modules/pi-antigravity/src/web-fetch/media.ts +11 -0
  72. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +9 -0
  73. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +93 -0
  74. package/node_modules/pi-antigravity/src/web-fetch/save.ts +71 -0
  75. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +138 -0
  76. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +9 -0
  77. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +957 -0
  78. package/node_modules/pi-antigravity/tsconfig.json +2 -2
  79. package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
  80. package/node_modules/pi-commandcode-provider/README.md +2 -2
  81. package/node_modules/pi-commandcode-provider/package.json +1 -1
  82. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +15 -9
  83. package/node_modules/pi-commandcode-provider/src/oauth.ts +69 -12
  84. package/node_modules/pi-lens/CHANGELOG-USER.md +6 -6
  85. package/node_modules/pi-lens/CHANGELOG.md +172 -0
  86. package/node_modules/pi-lens/README.md +103 -217
  87. package/node_modules/pi-lens/dist/{chunk-KXDQD34C.js → chunk-27JQHK7Y.js} +1 -1
  88. package/node_modules/pi-lens/dist/{chunk-W6VLB6LL.js → chunk-2APSZHHI.js} +61 -3
  89. package/node_modules/pi-lens/dist/{chunk-5EEWCJG7.js → chunk-2H5GHZKC.js} +8 -8
  90. package/node_modules/pi-lens/dist/{chunk-TS5EIWEF.js → chunk-2H7NFZ4Q.js} +11 -11
  91. package/node_modules/pi-lens/dist/{chunk-6GWCYEP7.js → chunk-37IDWT6O.js} +64 -16
  92. package/node_modules/pi-lens/dist/{chunk-OEPWTSUG.js → chunk-3PAS2ERX.js} +8 -8
  93. package/node_modules/pi-lens/dist/{chunk-ET3DSSFZ.js → chunk-3PO4YYOX.js} +9 -17
  94. package/node_modules/pi-lens/dist/{chunk-C6V2DSZZ.js → chunk-3QXFUP6T.js} +11 -11
  95. package/node_modules/pi-lens/dist/{chunk-HWMNTQBJ.js → chunk-3TSMQZG6.js} +32 -11
  96. package/node_modules/pi-lens/dist/{chunk-QY6J2FTK.js → chunk-4DAHGU3V.js} +15 -14
  97. package/node_modules/pi-lens/dist/{chunk-PCREZ4HJ.js → chunk-4IZZEN63.js} +33 -34
  98. package/node_modules/pi-lens/dist/{chunk-OYXD2MOM.js → chunk-5HBQL7DH.js} +2 -2
  99. package/node_modules/pi-lens/dist/{chunk-B4FAFEBP.js → chunk-5JB4WENL.js} +1 -1
  100. package/node_modules/pi-lens/dist/chunk-5YJXF2IS.js +56 -0
  101. package/node_modules/pi-lens/dist/{chunk-GHATCG2A.js → chunk-6CFSDLHE.js} +22 -18
  102. package/node_modules/pi-lens/dist/{chunk-FVQKX5KI.js → chunk-6E5QLMWI.js} +24 -22
  103. package/node_modules/pi-lens/dist/{chunk-AVBEPUCD.js → chunk-6GLMMGCX.js} +2 -2
  104. package/node_modules/pi-lens/dist/{chunk-YTXFNCVN.js → chunk-74AMPWNC.js} +2 -2
  105. package/node_modules/pi-lens/dist/{chunk-K2GV34T2.js → chunk-7CLWC2UH.js} +26 -37
  106. package/node_modules/pi-lens/dist/{chunk-MOEWCPMC.js → chunk-7DPXUPRF.js} +2 -2
  107. package/node_modules/pi-lens/dist/{chunk-7BEADGAZ.js → chunk-7U36VQL6.js} +2 -2
  108. package/node_modules/pi-lens/dist/{chunk-PPYUBO6Y.js → chunk-7WKVCZI4.js} +1 -1
  109. package/node_modules/pi-lens/dist/{chunk-ILC2B7IJ.js → chunk-7ZVTFLCC.js} +10 -10
  110. package/node_modules/pi-lens/dist/{chunk-IT7MFVGP.js → chunk-ADYQRETD.js} +2 -2
  111. package/node_modules/pi-lens/dist/{chunk-NCDH2JB7.js → chunk-ARTYCUGF.js} +25 -10
  112. package/node_modules/pi-lens/dist/{chunk-Z6WTLVUL.js → chunk-AXAR5ZW2.js} +225 -104
  113. package/node_modules/pi-lens/dist/{chunk-PK3GDU4M.js → chunk-AZG5UJYY.js} +1 -1
  114. package/node_modules/pi-lens/dist/{chunk-NRVWLTOY.js → chunk-B2OXE4AH.js} +60 -21
  115. package/node_modules/pi-lens/dist/{chunk-ORYQGVC3.js → chunk-B42AIWPJ.js} +2 -2
  116. package/node_modules/pi-lens/dist/{chunk-IC4L65U7.js → chunk-BBSDJTOV.js} +12 -13
  117. package/node_modules/pi-lens/dist/{chunk-HJWF7CGW.js → chunk-BKWFDWYM.js} +16 -16
  118. package/node_modules/pi-lens/dist/{chunk-D2ZYRI7M.js → chunk-C5PLBTNR.js} +1 -1
  119. package/node_modules/pi-lens/dist/{chunk-SRXYSLMW.js → chunk-CQY2HEH7.js} +1 -1
  120. package/node_modules/pi-lens/dist/{chunk-7424ANRU.js → chunk-CXQYK4YT.js} +1 -1
  121. package/node_modules/pi-lens/dist/{chunk-HYR25MV3.js → chunk-CZJGAOKL.js} +8 -7
  122. package/node_modules/pi-lens/dist/{chunk-DIIDMDZU.js → chunk-DCA2MXVQ.js} +11 -11
  123. package/node_modules/pi-lens/dist/{chunk-K2LD6YNH.js → chunk-DFKOA74L.js} +9 -9
  124. package/node_modules/pi-lens/dist/{chunk-AYDE7RFV.js → chunk-DI4AZZNY.js} +2 -2
  125. package/node_modules/pi-lens/dist/{chunk-6EXGCXM5.js → chunk-G53LBDNU.js} +99 -5
  126. package/node_modules/pi-lens/dist/chunk-GCSDF5IE.js +27 -0
  127. package/node_modules/pi-lens/dist/{chunk-5KLRCUDT.js → chunk-H5API74E.js} +6 -6
  128. package/node_modules/pi-lens/dist/chunk-HBX55MWO.js +27 -0
  129. package/node_modules/pi-lens/dist/{chunk-JRSS6KM4.js → chunk-HIJ4CHFF.js} +2 -2
  130. package/node_modules/pi-lens/dist/{chunk-3MHY4BQY.js → chunk-HIRBC72R.js} +4 -4
  131. package/node_modules/pi-lens/dist/{chunk-F7AMFFVK.js → chunk-HRLF35WL.js} +8 -8
  132. package/node_modules/pi-lens/dist/{chunk-HSTN27NR.js → chunk-I2FYOZNW.js} +9 -9
  133. package/node_modules/pi-lens/dist/{chunk-5FDUKJZO.js → chunk-I3NZVAMN.js} +9 -9
  134. package/node_modules/pi-lens/dist/{chunk-NZINZCHB.js → chunk-INBK3HIT.js} +3 -3
  135. package/node_modules/pi-lens/dist/{chunk-PXGVB2CY.js → chunk-J2ZB5MDS.js} +20 -18
  136. package/node_modules/pi-lens/dist/{chunk-HYDJUVOE.js → chunk-JGUDT5KD.js} +4 -4
  137. package/node_modules/pi-lens/dist/chunk-JOIKBUQN.js +88 -0
  138. package/node_modules/pi-lens/dist/{chunk-AZXTLZHE.js → chunk-K4Z7MK6T.js} +169 -165
  139. package/node_modules/pi-lens/dist/{chunk-WTSQKJAR.js → chunk-K7O6AHSJ.js} +10 -10
  140. package/node_modules/pi-lens/dist/{chunk-S6ZQFPOX.js → chunk-KNJH6WJQ.js} +6 -6
  141. package/node_modules/pi-lens/dist/{chunk-SUIZOCSY.js → chunk-KNSOA43J.js} +1 -1
  142. package/node_modules/pi-lens/dist/{chunk-3QMLB4TI.js → chunk-KXGTLAUW.js} +2 -2
  143. package/node_modules/pi-lens/dist/{chunk-OHEUOWYT.js → chunk-KZ732ZVW.js} +1 -1
  144. package/node_modules/pi-lens/dist/{chunk-G3LR6V6N.js → chunk-L6BDRYUK.js} +19 -17
  145. package/node_modules/pi-lens/dist/{chunk-OVPR3GQ6.js → chunk-LGH2HHZG.js} +24 -6
  146. package/node_modules/pi-lens/dist/{chunk-3R3Z54J7.js → chunk-LOEJFTF2.js} +1 -1
  147. package/node_modules/pi-lens/dist/{chunk-HGEE5LDW.js → chunk-LQQNFCQJ.js} +1 -1
  148. package/node_modules/pi-lens/dist/chunk-LVLPA32Q.js +810 -0
  149. package/node_modules/pi-lens/dist/chunk-M2YMBT5G.js +73 -0
  150. package/node_modules/pi-lens/dist/{chunk-Z2W5YJBW.js → chunk-MJRGPEQ5.js} +11 -11
  151. package/node_modules/pi-lens/dist/{chunk-3EIZMRXI.js → chunk-MOAVEPC4.js} +10 -10
  152. package/node_modules/pi-lens/dist/{chunk-TOOXNL6M.js → chunk-NGNBJIUO.js} +7 -7
  153. package/node_modules/pi-lens/dist/{chunk-AGEQRJ5A.js → chunk-NHA5K226.js} +1 -1
  154. package/node_modules/pi-lens/dist/{chunk-YLW26OHX.js → chunk-NNEQOC3U.js} +31 -59
  155. package/node_modules/pi-lens/dist/{chunk-ZWZD4TJ5.js → chunk-O2MHF7QM.js} +35 -36
  156. package/node_modules/pi-lens/dist/{chunk-PTJXMYRY.js → chunk-OLWGYBYT.js} +15 -16
  157. package/node_modules/pi-lens/dist/{chunk-JKAVKTMY.js → chunk-OZQQ3AIR.js} +17 -20
  158. package/node_modules/pi-lens/dist/{chunk-6JLNZ6DP.js → chunk-P5MSLVUW.js} +10 -10
  159. package/node_modules/pi-lens/dist/{chunk-OF2YGDUE.js → chunk-PFJLYRO3.js} +37 -38
  160. package/node_modules/pi-lens/dist/chunk-PKWEBMCA.js +2957 -0
  161. package/node_modules/pi-lens/dist/{chunk-JLMS7EMD.js → chunk-PPQHMSPH.js} +16 -15
  162. package/node_modules/pi-lens/dist/{chunk-6EIV3H7O.js → chunk-PQF6YGYB.js} +12 -5
  163. package/node_modules/pi-lens/dist/{chunk-VU2PRGRI.js → chunk-PQXUZYTQ.js} +4 -4
  164. package/node_modules/pi-lens/dist/{chunk-MV6ST2KT.js → chunk-Q7J3JYJ2.js} +13 -12
  165. package/node_modules/pi-lens/dist/{chunk-BMMRLJA4.js → chunk-QE5DJ7MX.js} +27 -10
  166. package/node_modules/pi-lens/dist/{chunk-IZ36G463.js → chunk-QE7BJQ6K.js} +7 -7
  167. package/node_modules/pi-lens/dist/{chunk-E5SSUV2A.js → chunk-QMWKSYWB.js} +4 -4
  168. package/node_modules/pi-lens/dist/{chunk-QJ4T73J5.js → chunk-QV3JPCMK.js} +1 -1
  169. package/node_modules/pi-lens/dist/{chunk-3PMLYGJN.js → chunk-R4L7KZ7R.js} +5 -5
  170. package/node_modules/pi-lens/dist/{chunk-7ZVEFWOE.js → chunk-RIH3UBK4.js} +10 -10
  171. package/node_modules/pi-lens/dist/{chunk-T5EGSBM2.js → chunk-RJ3APNIP.js} +3 -3
  172. package/node_modules/pi-lens/dist/{chunk-AAIVSSUU.js → chunk-S6MCMD27.js} +35 -12
  173. package/node_modules/pi-lens/dist/{chunk-SF7KSXB5.js → chunk-SCU62JLX.js} +6 -6
  174. package/node_modules/pi-lens/dist/{chunk-FDLGJFAE.js → chunk-SDYLT45T.js} +3 -3
  175. package/node_modules/pi-lens/dist/chunk-TFKN5EIR.js +27 -0
  176. package/node_modules/pi-lens/dist/{chunk-Y7XMKBFP.js → chunk-TKOFTLGB.js} +34 -26
  177. package/node_modules/pi-lens/dist/chunk-TQWRH25U.js +35 -0
  178. package/node_modules/pi-lens/dist/{chunk-DZSQXG66.js → chunk-TWEOJE3D.js} +277 -62
  179. package/node_modules/pi-lens/dist/{chunk-R67WQ5RY.js → chunk-UN72ZAJ5.js} +8 -8
  180. package/node_modules/pi-lens/dist/{chunk-AD7JDEI6.js → chunk-UNP6Y4JV.js} +16 -16
  181. package/node_modules/pi-lens/dist/{chunk-D6ANA6YU.js → chunk-VGRGW4UL.js} +63 -55
  182. package/node_modules/pi-lens/dist/{chunk-DFAY7JUN.js → chunk-VSQT6IHZ.js} +2 -2
  183. package/node_modules/pi-lens/dist/{chunk-7T64QA5D.js → chunk-VWEBZ2JV.js} +39 -38
  184. package/node_modules/pi-lens/dist/{chunk-HRQTYU2T.js → chunk-W26QZ3OM.js} +1 -1
  185. package/node_modules/pi-lens/dist/{chunk-2HWVG3IM.js → chunk-XDNWR7SG.js} +2 -2
  186. package/node_modules/pi-lens/dist/{chunk-75TVYCQW.js → chunk-XSC3BCN3.js} +5 -5
  187. package/node_modules/pi-lens/dist/{chunk-ME6MF2N2.js → chunk-YCR6ZYTE.js} +1 -1
  188. package/node_modules/pi-lens/dist/{chunk-LD7SXICE.js → chunk-ZI7YHV6I.js} +5 -5
  189. package/node_modules/pi-lens/dist/{chunk-E3PNZDPH.js → chunk-ZQSSO7LO.js} +33 -1
  190. package/node_modules/pi-lens/dist/{chunk-T6PPK3T6.js → chunk-ZULZS2I6.js} +385 -407
  191. package/node_modules/pi-lens/dist/index.js +6508 -5413
  192. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +9 -9
  193. package/node_modules/pi-lens/dist/mcp/cli.js +39 -38
  194. package/node_modules/pi-lens/dist/mcp/server.js +602 -345
  195. package/node_modules/pi-lens/dist/mcp/worker.js +57 -58
  196. package/node_modules/pi-lens/dist/probes/installer.js +19 -17
  197. package/node_modules/pi-lens/docs/architecture.md +113 -0
  198. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +2 -2
  199. package/node_modules/pi-lens/docs/ci.md +18 -4
  200. package/node_modules/pi-lens/docs/defect-shapes.md +41 -3
  201. package/node_modules/pi-lens/docs/dependencies.md +10 -10
  202. package/node_modules/pi-lens/docs/features.md +3 -3
  203. package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +13 -1
  204. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +19 -0
  205. package/node_modules/pi-lens/docs/language-coverage.md +39 -0
  206. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +10 -4
  207. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +1 -1
  208. package/node_modules/pi-lens/docs/pi-lens-fixer.md +4 -0
  209. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +1 -1
  210. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +4 -5
  211. package/node_modules/pi-lens/docs/pi-lens-subagent.md +5 -2
  212. package/node_modules/pi-lens/docs/prose-standard.md +112 -0
  213. package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
  214. package/node_modules/pi-lens/docs/usage.md +50 -0
  215. package/node_modules/pi-lens/package.json +1 -1
  216. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/array-callback-return-js-test.yml +23 -0
  217. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/array-callback-return-test.yml +23 -0
  218. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-negation-in-equality-check-js-test.yml +8 -0
  219. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-negation-in-equality-check-test.yml +8 -0
  220. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-throwing-call-js-test.yml +16 -0
  221. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-throwing-call-test.yml +16 -0
  222. package/node_modules/pi-lens/rules/ast-grep-rules/rules/array-callback-return-js.yml +8 -0
  223. package/node_modules/pi-lens/rules/ast-grep-rules/rules/array-callback-return.yml +8 -0
  224. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-negation-in-equality-check-js.yml +17 -5
  225. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-negation-in-equality-check.yml +17 -5
  226. package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-throwing-call-js.yml +8 -1
  227. package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-throwing-call.yml +8 -1
  228. package/node_modules/pi-lens/rules/tree-sitter-queries/typescript/ts-react-antipatterns.yml +8 -0
  229. package/node_modules/pi-web-access/CHANGELOG.md +29 -0
  230. package/node_modules/pi-web-access/README.md +35 -15
  231. package/node_modules/pi-web-access/anysearch.ts +7 -3
  232. package/node_modules/pi-web-access/autom.ts +196 -0
  233. package/node_modules/pi-web-access/cloro.ts +254 -0
  234. package/node_modules/pi-web-access/curator-page.ts +7 -1
  235. package/node_modules/pi-web-access/curator-server.ts +3 -0
  236. package/node_modules/pi-web-access/dist/index.js +12931 -12111
  237. package/node_modules/pi-web-access/dist/mcp-cli.js +1188 -416
  238. package/node_modules/pi-web-access/domain-filter-normalization.ts +30 -0
  239. package/node_modules/pi-web-access/duckduckgo-rate-limit.ts +144 -34
  240. package/node_modules/pi-web-access/duckduckgo.ts +11 -3
  241. package/node_modules/pi-web-access/extract.ts +60 -4
  242. package/node_modules/pi-web-access/gemini-search.ts +25 -5
  243. package/node_modules/pi-web-access/index.ts +9 -1
  244. package/node_modules/pi-web-access/package.json +2 -2
  245. package/node_modules/pi-web-access/page-query.ts +12 -3
  246. package/node_modules/pi-web-access/specstream.ts +276 -0
  247. package/node_modules/pi-web-access/tool-activation.ts +21 -6
  248. package/node_modules/pi-web-access/utils.ts +4 -0
  249. package/node_modules/pi-web-access/video-extract.ts +2 -2
  250. package/node_modules/pi-web-access/web-tool-core.ts +24 -5
  251. package/node_modules/pi-web-access/youtube-extract.ts +2 -2
  252. package/package.json +13 -7
  253. package/node_modules/pi-lens/dist/chunk-3VWEZ6H2.js +0 -72
  254. package/node_modules/pi-lens/dist/chunk-7KWI5UHL.js +0 -28
  255. package/node_modules/pi-lens/dist/chunk-7M64NTAK.js +0 -38
  256. package/node_modules/pi-lens/dist/chunk-BEIPWPVR.js +0 -1037
  257. package/node_modules/pi-lens/dist/chunk-D7OEGXDX.js +0 -2417
  258. package/node_modules/pi-lens/dist/chunk-KUDUKKQE.js +0 -89
  259. package/node_modules/pi-lens/dist/chunk-TM3A3K7T.js +0 -28
  260. package/node_modules/pi-lens/dist/chunk-VD7MQFEV.js +0 -56
  261. package/node_modules/pi-lens/dist/chunk-YLHJWAQS.js +0 -256
  262. package/node_modules/pi-lens/dist/chunk-YULIERZW.js +0 -27
@@ -0,0 +1,83 @@
1
+ import { createDocument } from "@mixmark-io/domino";
2
+ import { repairText } from "../utils/text.js";
3
+
4
+ /** Work limits apply before the recursive DOM parser or converter sees a document. */
5
+ export const MAX_DOCUMENT_CHARS = 2_000_000;
6
+ const MAX_DOCUMENT_DEPTH = 128;
7
+ export const MAX_DOCUMENT_NODES = 50_000;
8
+ const VOID = new Set(
9
+ "area base br col embed hr img input link meta param source track wbr".split(" "),
10
+ );
11
+ const TOKENS =
12
+ /<!--[\s\S]*?(?:-->|$)|<(script|style|textarea|title|noscript|xmp|iframe|noembed|noframes|plaintext)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)|<\/?([a-z][\w:-]*)\b(?:[^"'<>]|"[^"]*"|'[^']*')*>/gi;
13
+
14
+ /** The page is beyond what the converter will take on; the source itself is fine. */
15
+ export class DocumentLimitError extends Error {
16
+ constructor(message: string) {
17
+ super(message);
18
+ this.name = "DocumentLimitError";
19
+ }
20
+ }
21
+
22
+ /**
23
+ * The parser accepts tag names such as `a<a` that the DOM later refuses to clone, which
24
+ * would fail the whole read at conversion. Replace each with a span holding its children.
25
+ */
26
+ function neutralizeInvalidElements(document: Document): void {
27
+ for (const element of Array.from(document.querySelectorAll("*"))) {
28
+ try {
29
+ document.createElement(element.localName);
30
+ continue;
31
+ } catch {
32
+ // Invalid name: replace below.
33
+ }
34
+ const span = document.createElement("span");
35
+ while (element.firstChild) span.appendChild(element.firstChild);
36
+ element.parentNode?.replaceChild(span, element);
37
+ }
38
+ }
39
+
40
+ /** Reject bounded-but-pathological input with an actionable page-level error. */
41
+ export function parseDocument(source: string): Document {
42
+ if (source.length > MAX_DOCUMENT_CHARS)
43
+ throw new DocumentLimitError(
44
+ "The page is too large to convert safely. Open it in a browser or request a smaller page.",
45
+ );
46
+ const stack: string[] = [];
47
+ let nodes = 0;
48
+ for (const match of source.matchAll(TOKENS)) {
49
+ if (++nodes > MAX_DOCUMENT_NODES)
50
+ throw new DocumentLimitError(
51
+ "The page has too many elements to convert safely. Open it in a browser.",
52
+ );
53
+ const tag = match[2]?.toLowerCase();
54
+ if (!tag || VOID.has(tag)) continue;
55
+ if (match[0].startsWith("</")) {
56
+ const index = stack.lastIndexOf(tag);
57
+ if (index >= 0) stack.length = index;
58
+ } else {
59
+ // Optional end tags close a sibling and its descendants, not merely the
60
+ // stack's top. Respect list/table boundaries so nested containers remain nested.
61
+ const closeSibling = (names: string[], boundaries: string[]) => {
62
+ const sibling = Math.max(...names.map((name) => stack.lastIndexOf(name)));
63
+ const boundary = Math.max(-1, ...boundaries.map((name) => stack.lastIndexOf(name)));
64
+ if (sibling > boundary) stack.length = sibling;
65
+ };
66
+ if (/^(?:p|div|section|article|main|h[1-6]|ul|ol|table|blockquote)$/.test(tag))
67
+ closeSibling(["p"], []);
68
+ if (tag === "li") closeSibling(["li"], ["ul", "ol"]);
69
+ if (tag === "dt" || tag === "dd") closeSibling(["dt", "dd"], ["dl"]);
70
+ if (tag === "tr") closeSibling(["tr"], ["table"]);
71
+ if (tag === "td" || tag === "th") closeSibling(["td", "th"], ["tr"]);
72
+ if (tag === "option") closeSibling(["option"], ["select", "datalist"]);
73
+ stack.push(tag);
74
+ if (stack.length > MAX_DOCUMENT_DEPTH)
75
+ throw new DocumentLimitError(
76
+ "The page is nested too deeply to convert safely. Open it in a browser.",
77
+ );
78
+ }
79
+ }
80
+ const document = createDocument(repairText(source));
81
+ neutralizeInvalidElements(document);
82
+ return document;
83
+ }
@@ -0,0 +1,24 @@
1
+ /** CommonMark fenced blocks, including blockquote containers. */
2
+ export const FENCE_LINE = /^ {0,3}((?:>\s*)*)(`{3,}|~{3,})(.*)$/;
3
+ export type Fence = { marker: string; length: number; prefix: string };
4
+
5
+ export function advanceFence(open: Fence | undefined, line: string): Fence | undefined {
6
+ const match = FENCE_LINE.exec(line);
7
+ if (!match) return open;
8
+ const [, prefix, delimiter, rest] = match;
9
+ if (!open) {
10
+ if (delimiter[0] === "`" && rest.includes("`")) return undefined;
11
+ return { marker: delimiter[0], length: delimiter.length, prefix };
12
+ }
13
+ return delimiter[0] === open.marker &&
14
+ delimiter.length >= open.length &&
15
+ prefix === open.prefix &&
16
+ !rest.trim()
17
+ ? undefined
18
+ : open;
19
+ }
20
+ export function unclosedFence(text: string): Fence | undefined {
21
+ let open: Fence | undefined;
22
+ for (const line of text.split("\n")) open = advanceFence(open, line);
23
+ return open;
24
+ }
@@ -0,0 +1,97 @@
1
+ import type { WebFetchResult } from "./web-fetch.js";
2
+ import { DEFAULT_WEB_FETCH_MAX_CHARS } from "./limits.js";
3
+ import { METADATA_LIMITS } from "./metadata.js";
4
+ import { cleanText, elideMiddle } from "../utils/text.js";
5
+ import { redactSecrets } from "../utils/security.js";
6
+
7
+ const sanitizeMetadataText = cleanText;
8
+
9
+ /** Format the page header, with bounded fields and redacted URLs. */
10
+ export function formatWebFetchHeader(result: WebFetchResult): string {
11
+ const maxChars = result.maxChars ?? DEFAULT_WEB_FETCH_MAX_CHARS;
12
+ // Provenance must fit inside the output budget, so a long URL cannot take it all.
13
+ const headerBudget = Math.max(0, maxChars - Math.min(256, Math.floor(maxChars / 4)));
14
+ const dropped = new Set<string>();
15
+ const build = (urlLimit: number, titleLimit: number): string[] => {
16
+ const text = (value: string | undefined, limit: number) =>
17
+ sanitizeMetadataText(value === undefined ? undefined : redactSecrets(value), limit);
18
+ const header = [
19
+ "Page metadata (publisher claims):",
20
+ `Title: ${text(result.title, titleLimit) ?? "Untitled page"}`,
21
+ ];
22
+ const add = (label: string, value: string | undefined) => {
23
+ if (value === undefined || dropped.has(label)) return;
24
+ header.push(`${label}: ${value}`);
25
+ };
26
+ add("Description", text(result.description, METADATA_LIMITS.description));
27
+ add("Updated", text(result.updated, METADATA_LIMITS.updated));
28
+ add("Author", text(result.author, METADATA_LIMITS.author));
29
+ add("Published", text(result.published, METADATA_LIMITS.published));
30
+ add("Language", text(result.language, METADATA_LIMITS.language));
31
+ const url = (value: string) =>
32
+ elideMiddle(sanitizeMetadataText(redactSecrets(value), 4_096) ?? "", urlLimit);
33
+ if (result.representationUrl) header.push(`Representation: ${url(result.representationUrl)}`);
34
+ if (!dropped.has("Retrieval") && result.attempts && result.attempts.length > 1) {
35
+ const attempts = result.attempts.map(
36
+ (attempt) =>
37
+ `${attempt.stage ?? attempt.source}@${attempt.endpoint ? new URL(attempt.endpoint).hostname : "Google"}: ${text(attempt.outcome, 200) ?? ""}`,
38
+ );
39
+ header.push(`Retrieval: ${attempts.join(" → ")}`);
40
+ }
41
+ if (result.assessment && result.assessment !== "readable") {
42
+ header.push(
43
+ `Content assessment: ${result.assessment} (heuristic; source completeness does not establish article coverage).`,
44
+ );
45
+ }
46
+ header.push("Retrieval provenance:");
47
+ const requestedUrl = url(result.requestedUrl);
48
+ const resolvedUrl = url(result.resolvedUrl);
49
+ if (result.redirected || result.requestedUrl !== result.resolvedUrl)
50
+ header.push(`Requested: ${requestedUrl}`);
51
+ header.push(`Source: ${resolvedUrl} (${result.source === "live" ? "live" : "cache"})`);
52
+ if (result.assessment === "empty" || result.assessment === "suspected-access-wall") {
53
+ header.push(
54
+ "Note: no reliable article was identified. Open the page in a browser or use another permitted source; do not keep retrying this URL.",
55
+ );
56
+ }
57
+ if (result.assessment === "suspected-shell") {
58
+ header.push(
59
+ "Note: this appears to be a JavaScript-rendered page; this tool cannot render it. Open it in a browser.",
60
+ );
61
+ }
62
+ if (result.partial === true) {
63
+ header.push(
64
+ result.content.trim()
65
+ ? "Note: the crawler's copy ends mid-page, so some content may be missing."
66
+ : "Note: the crawler's copy ends mid-page and holds no readable content.",
67
+ );
68
+ } else if (result.partial === null) {
69
+ header.push(
70
+ result.content.trim()
71
+ ? "Note: the crawler's copy has no clear end marker, so completeness is unknown."
72
+ : "Note: the crawler's copy has no clear end marker and holds no readable content.",
73
+ );
74
+ }
75
+ for (const note of result.notes ?? []) add("Note", text(note, 300));
76
+ return header;
77
+ };
78
+ let urlLimit = Math.max(64, Math.min(2_048, Math.floor(headerBudget / 4)));
79
+ let titleLimit: number = METADATA_LIMITS.title;
80
+ let header = build(urlLimit, titleLimit);
81
+ // Optional metadata must not crowd provenance and the next captured range out.
82
+ for (const label of ["Description", "Updated", "Author", "Published", "Language", "Retrieval"]) {
83
+ if (header.join("\n").length + 7 <= headerBudget) break;
84
+ dropped.add(label);
85
+ header = build(urlLimit, titleLimit);
86
+ }
87
+ // A long URL must not crowd out the page content either.
88
+ while (header.join("\n").length + 7 > headerBudget && urlLimit > 64) {
89
+ urlLimit = Math.max(64, Math.floor(urlLimit / 2));
90
+ header = build(urlLimit, titleLimit);
91
+ }
92
+ while (header.join("\n").length + 7 > headerBudget && titleLimit > 40) {
93
+ titleLimit = Math.max(40, Math.floor(titleLimit / 2));
94
+ header = build(urlLimit, titleLimit);
95
+ }
96
+ return `${header.join("\n")}\n\n---\n\n`;
97
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./markdown.js";
2
+ export * from "./save.js";
3
+ export * from "./web-fetch.js";
@@ -0,0 +1,328 @@
1
+ import { parseDocument } from "./document.js";
2
+ import { advanceFence, FENCE_LINE, type Fence } from "./fences.js";
3
+ import { repairText } from "../utils/text.js";
4
+ import { isRecord } from "../utils/util.js";
5
+ import { METADATA_LIMITS } from "./metadata.js";
6
+ import {
7
+ classifyCopyCompleteness,
8
+ extractPageMetadata,
9
+ htmlToMarkdown,
10
+ looksLikeHtml,
11
+ sanitizeMetadataText,
12
+ } from "./markdown.js";
13
+
14
+ export type ContentAssessment = "readable" | "empty" | "suspected-shell" | "suspected-access-wall";
15
+
16
+ export type PageInspection = {
17
+ rendered: string;
18
+ completeness: "complete" | "incomplete" | "unknown";
19
+ assessment: ContentAssessment;
20
+ notes?: string[];
21
+ metadata: ReturnType<typeof extractPageMetadata> & {
22
+ author?: string;
23
+ published?: string;
24
+ language?: string;
25
+ };
26
+ alternates: Array<{
27
+ url: string;
28
+ type: "text/markdown" | "application/json";
29
+ language?: string;
30
+ }>;
31
+ };
32
+
33
+ function normalizedWallHeading(value: string): string {
34
+ return value
35
+ .replace(/\s*[|•–—-]\s*cloudflare\s*$/i, "")
36
+ .replace(/\s+/g, " ")
37
+ .trim();
38
+ }
39
+
40
+ /**
41
+ * Headings that are a wall on their own. They stay exact: "429 Too Many Requests"
42
+ * is also the title of a real article about that status, and "Forbidden error
43
+ * handling" is a real article title.
44
+ */
45
+ const ACCESS_WALL_HEADINGS = [
46
+ "forbidden",
47
+ "403 forbidden",
48
+ "unauthorized",
49
+ "401 unauthorized",
50
+ "access denied",
51
+ ];
52
+
53
+ /**
54
+ * Openings of the interstitials that stand in for an article. The heading of a real
55
+ * wall usually carries more than the phrase itself ("Please enable JavaScript to
56
+ * continue"), so a phrase that opens the heading marks a wall.
57
+ */
58
+ const ACCESS_WALL_OPENINGS = [
59
+ "just a moment",
60
+ "just a second",
61
+ "one more step",
62
+ "robot or human",
63
+ "please wait while we verify",
64
+ "access to this page has been denied",
65
+ "you don't have permission",
66
+ "verifying your browser",
67
+ "too many requests",
68
+ "verify you are human",
69
+ "verifying you are human",
70
+ "attention required",
71
+ "you have been blocked",
72
+ "sorry, you have been blocked",
73
+ "checking your browser",
74
+ "security check",
75
+ "enable javascript",
76
+ "please enable javascript",
77
+ "javascript is required",
78
+ "javascript required",
79
+ "are you a robot",
80
+ "unusual traffic",
81
+ "request blocked",
82
+ "rate limited",
83
+ "you are being rate limited",
84
+ ];
85
+
86
+ /** Sign-in pages read like a wall, but an article title may also start with one. */
87
+ const ACCESS_WALL_SIGN_IN_OPENINGS = ["sign in", "log in"];
88
+
89
+ /** How much text may follow the wall phrase before the heading is an article title. */
90
+ const ACCESS_WALL_TAIL = 40;
91
+ const ACCESS_WALL_SIGN_IN_TAIL = 24;
92
+
93
+ /** A short block/sign-in heading, not an article that happens to discuss one. */
94
+ function isAccessWallHeading(value: string | undefined): boolean {
95
+ if (!value) return false;
96
+ const text = normalizedWallHeading(value).toLowerCase();
97
+ if (!text) return false;
98
+ if (ACCESS_WALL_HEADINGS.includes(text.replace(/[.!…\s]*$/, ""))) return true;
99
+ const opens = (opening: string, tail: number) =>
100
+ text.startsWith(opening) &&
101
+ (text.length - opening.length <= tail || /browser|human|verify|access/.test(text));
102
+ return (
103
+ ACCESS_WALL_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_TAIL)) ||
104
+ ACCESS_WALL_SIGN_IN_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_SIGN_IN_TAIL))
105
+ );
106
+ }
107
+
108
+ /** A wall heading alone cannot overrule substantial article content. */
109
+ function hasArticleContent(rendered: string): boolean {
110
+ const body = rendered.replace(/^#{1,6} .*$/gm, "").trim();
111
+ return (
112
+ (body.length >= 500 && /[.!?:]/.test(body)) ||
113
+ (body.length >= 80 && /\b(?:HTTP|status code|response|client|server)\b/i.test(body))
114
+ );
115
+ }
116
+
117
+ function isLoadingShell(rendered: string): boolean {
118
+ const visible = rendered.replace(/^#{1,6} .*$/gm, "").trim();
119
+ return /^(?:loading|please wait|redirecting|initializing)[.!…\s]*$/i.test(visible);
120
+ }
121
+
122
+ /** Match structured data to this page without treating fragments as separate pages. */
123
+ function pageIdentity(value: unknown, baseUrl: string): string | undefined {
124
+ if (isRecord(value)) value = value["@id"];
125
+ if (typeof value !== "string") return undefined;
126
+ try {
127
+ const url = new URL(value, baseUrl);
128
+ url.hash = "";
129
+ return url.href;
130
+ } catch {
131
+ return undefined;
132
+ }
133
+ }
134
+
135
+ /** Inspect data before destructive Markdown cleanup; never execute page scripts. */
136
+ export function inspectPage(content: string, url: string, contentType?: string): PageInspection {
137
+ if (!looksLikeHtml(content, contentType)) {
138
+ const rendered = repairText(content).trim();
139
+ let title: string | undefined;
140
+ let fence: Fence | undefined;
141
+ for (const line of rendered.split("\n")) {
142
+ const previous = fence;
143
+ fence = advanceFence(fence, line);
144
+ if (!previous && !fence && !FENCE_LINE.test(line)) {
145
+ title = /^ {0,3}# +(.+?)(?: +#+)?\s*$/.exec(line)?.[1];
146
+ if (title) break;
147
+ }
148
+ }
149
+ return {
150
+ rendered,
151
+ completeness: "unknown",
152
+ assessment: rendered ? "readable" : "empty",
153
+ metadata: { title: sanitizeMetadataText(title, 300) },
154
+ alternates: [],
155
+ };
156
+ }
157
+ const document = parseDocument(content);
158
+ const metadata: PageInspection["metadata"] = extractPageMetadata(content, document);
159
+ metadata.language = sanitizeMetadataText(document.documentElement.lang || undefined, 50);
160
+ const nodes: Record<string, unknown>[] = [];
161
+ let budget = 256_000;
162
+ for (const script of Array.from(
163
+ document.querySelectorAll('script[type="application/ld+json"]'),
164
+ ).slice(0, 16)) {
165
+ const text = script.textContent ?? "";
166
+ budget -= text.length;
167
+ if (budget < 0) break;
168
+ try {
169
+ const value: unknown = JSON.parse(text);
170
+ const roots = Array.isArray(value) ? value : [value];
171
+ for (const root of roots) {
172
+ if (!isRecord(root)) continue;
173
+ nodes.push(root);
174
+ if (Array.isArray(root["@graph"])) nodes.push(...root["@graph"].filter(isRecord));
175
+ }
176
+ } catch {
177
+ // Invalid or truncated structured data is not evidence.
178
+ }
179
+ }
180
+ const identity = pageIdentity(url, url);
181
+ const article = nodes.find((node) => {
182
+ const types = Array.isArray(node["@type"]) ? node["@type"] : [node["@type"]];
183
+ return (
184
+ types.some(
185
+ (type) =>
186
+ typeof type === "string" && /^(Article|NewsArticle|BlogPosting|TechArticle)$/.test(type),
187
+ ) &&
188
+ [node.url, node.mainEntityOfPage, node["@id"]].some(
189
+ (value) => pageIdentity(value, url) === identity,
190
+ )
191
+ );
192
+ });
193
+ if (article) {
194
+ const text = (value: unknown, field: keyof typeof METADATA_LIMITS) =>
195
+ typeof value === "string" && value.trim()
196
+ ? sanitizeMetadataText(value, METADATA_LIMITS[field])
197
+ : undefined;
198
+ metadata.title ??= text(article.headline, "title");
199
+ metadata.description ??= text(article.description, "description");
200
+ metadata.updated ??= text(article.dateModified, "updated");
201
+ metadata.published = text(article.datePublished, "published");
202
+ metadata.language ??= text(article.inLanguage, "language");
203
+ const author: unknown = Array.isArray(article.author) ? article.author[0] : article.author;
204
+ const person: unknown =
205
+ isRecord(author) && !author.name && typeof author["@id"] === "string"
206
+ ? nodes.find((node) => node["@id"] === author["@id"])
207
+ : author;
208
+ metadata.author = isRecord(person) ? text(person.name, "author") : text(person, "author");
209
+ }
210
+
211
+ const alternates: PageInspection["alternates"] = [];
212
+ for (const link of Array.from(document.querySelectorAll("link[href][type]"))) {
213
+ if (!(link.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).includes("alternate"))
214
+ continue;
215
+ const type = link.getAttribute("type")?.split(";")[0].toLowerCase().trim();
216
+ if (type !== "text/markdown" && type !== "application/json") continue;
217
+ try {
218
+ const alternate = new URL(link.getAttribute("href")!, url);
219
+ if (alternate.origin !== new URL(url).origin || alternate.username || alternate.password)
220
+ continue;
221
+ if (/\.pdf$/i.test(alternate.pathname)) continue;
222
+ alternate.hash = "";
223
+ if (alternate.href === identity || alternates.some((item) => item.url === alternate.href))
224
+ continue;
225
+ const language = sanitizeMetadataText(
226
+ link.getAttribute("hreflang") ?? undefined,
227
+ 35,
228
+ )?.toLowerCase();
229
+ const declaredLanguage = language && language !== "x-default" ? language : undefined;
230
+ alternates.push({
231
+ url: alternate.href,
232
+ type,
233
+ ...(declaredLanguage ? { language: declaredLanguage } : {}),
234
+ });
235
+ } catch {
236
+ // Ignore invalid URLs, including malformed base-relative references.
237
+ }
238
+ }
239
+ const pageLanguage = metadata.language?.split("-")[0].toLowerCase();
240
+ const sameLanguage = pageLanguage
241
+ ? alternates.filter((item) => !item.language || item.language.split("-")[0] === pageLanguage)
242
+ : alternates;
243
+ const preferred = sameLanguage.length ? sameLanguage : alternates;
244
+ preferred.sort((a, b) => Number(b.type === "text/markdown") - Number(a.type === "text/markdown"));
245
+ const appScript = Boolean(document.querySelector('script[src], script[type="module"]'));
246
+ const rendered = htmlToMarkdown(content, { baseUrl: url, document });
247
+ const heading = /^# +(.+)$/m.exec(rendered)?.[1] || "";
248
+ // A page that loads an application script and shows nothing else is a shell.
249
+ const completeness = classifyCopyCompleteness(content);
250
+ // A page that loads application JavaScript and shows only a placeholder is a shell.
251
+ // A cut-off copy holding only a heading has lost its body; report it as empty.
252
+ const bodyMissing =
253
+ !rendered.trim() ||
254
+ (completeness === "incomplete" && !rendered.replace(/^#{1,6} .*$/gm, "").trim());
255
+ const assessment: ContentAssessment = bodyMissing
256
+ ? // A copy that ends before the content is cut off, not an application shell.
257
+ appScript && completeness !== "incomplete"
258
+ ? "suspected-shell"
259
+ : "empty"
260
+ : isAccessWallHeading(heading || metadata.title) &&
261
+ /\b(?:check(?:ing)?|verif\w*|captcha|blocked|denied|permission|enable javascript|sign in|log in)\b/i.test(
262
+ rendered.replace(/^#{1,6} .*$/gm, ""),
263
+ ) &&
264
+ !hasArticleContent(rendered)
265
+ ? "suspected-access-wall"
266
+ : appScript && isLoadingShell(rendered)
267
+ ? "suspected-shell"
268
+ : "readable";
269
+ return {
270
+ rendered,
271
+ completeness,
272
+ assessment,
273
+ metadata,
274
+ alternates: preferred.slice(0, 8),
275
+ };
276
+ }
277
+
278
+ /**
279
+ * Inspection of a source the converter will not take on. Raw mode returns the crawled
280
+ * source as it is, so the page's size limits the answer, not the read.
281
+ */
282
+ export function inspectUnconverted(content: string, reason: string): PageInspection {
283
+ return {
284
+ rendered: "",
285
+ completeness: classifyCopyCompleteness(content),
286
+ assessment: content.trim() ? "readable" : "empty",
287
+ notes: [`Not converted: ${reason}`],
288
+ metadata: {},
289
+ alternates: [],
290
+ };
291
+ }
292
+
293
+ /** Decode only explicit article-body JSON shapes from an advertised representation. */
294
+ export function articleRepresentation(content: string, articleUrl: string): string | undefined {
295
+ let value: unknown;
296
+ try {
297
+ value = JSON.parse(content);
298
+ } catch {
299
+ return undefined;
300
+ }
301
+ if (!isRecord(value)) return undefined;
302
+ // GitHub Docs article API.
303
+ if (
304
+ isRecord(value.meta) &&
305
+ value.meta.documentType === "article" &&
306
+ typeof value.body === "string" &&
307
+ Array.isArray(value.meta.breadcrumbs)
308
+ ) {
309
+ const current: unknown = value.meta.breadcrumbs.at(-1);
310
+ if (
311
+ isRecord(current) &&
312
+ pageIdentity(current.href, articleUrl) === pageIdentity(articleUrl, articleUrl)
313
+ )
314
+ return value.body;
315
+ }
316
+ // WordPress single-post REST representation (not an index or oEmbed summary).
317
+ if (
318
+ typeof value.id === "number" &&
319
+ typeof value.link === "string" &&
320
+ pageIdentity(value.link, articleUrl) === pageIdentity(articleUrl, articleUrl) &&
321
+ isRecord(value.content) &&
322
+ value.content.protected !== true &&
323
+ typeof value.content.rendered === "string"
324
+ ) {
325
+ return value.content.rendered;
326
+ }
327
+ return undefined;
328
+ }
@@ -0,0 +1,4 @@
1
+ /** Defaults and limits shared by retrieval and display. */
2
+ export const DEFAULT_WEB_FETCH_MAX_CHARS = 60_000;
3
+ export const WEB_FETCH_TIMEOUT_MS = 10_000;
4
+ export const MAX_RESPONSE_BYTES = 5_000_000;