docpull 6.8.0__tar.gz → 6.10.0__tar.gz

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 (267) hide show
  1. {docpull-6.8.0/src/docpull.egg-info → docpull-6.10.0}/PKG-INFO +1 -1
  2. {docpull-6.8.0 → docpull-6.10.0}/pyproject.toml +4 -1
  3. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/__init__.py +1 -1
  4. docpull-6.10.0/src/docpull/_fileutil.py +89 -0
  5. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/basis.py +8 -1
  6. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/cache/manager.py +128 -27
  7. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/change_events.py +47 -16
  8. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/cli.py +58 -4
  9. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/compat_jobs.py +71 -13
  10. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_ci.py +19 -10
  11. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/cli.py +4 -1
  12. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_query.py +44 -22
  13. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/core/fetcher.py +84 -2
  14. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/composite.py +6 -0
  15. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/sitemap.py +41 -3
  16. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/document_parse.py +7 -2
  17. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/eval_grade.py +4 -2
  18. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/frozen.py +9 -1
  19. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/http/client.py +8 -0
  20. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/http/rate_limiter.py +11 -0
  21. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/mcp/server.py +1 -1
  22. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/mcp/tools.py +179 -98
  23. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/config.py +28 -1
  24. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/events.py +2 -0
  25. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/monitor.py +58 -4
  26. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/output_contract.py +26 -12
  27. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pack_reader.py +22 -15
  28. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pack_tools.py +2 -2
  29. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/manifest.py +27 -0
  30. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/fetch.py +55 -0
  31. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/save.py +5 -0
  32. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/save_json.py +12 -4
  33. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/project.py +182 -24
  34. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/redaction.py +28 -18
  35. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/rendering.py +98 -3
  36. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/server.py +9 -1
  37. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/skill_export.py +11 -1
  38. docpull-6.10.0/src/docpull/state_paths.py +51 -0
  39. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/surface.py +1 -1
  40. {docpull-6.8.0 → docpull-6.10.0/src/docpull.egg-info}/PKG-INFO +1 -1
  41. {docpull-6.8.0 → docpull-6.10.0}/src/docpull.egg-info/SOURCES.txt +6 -3
  42. docpull-6.10.0/tests/test_audit_cache_mcp.py +338 -0
  43. docpull-6.10.0/tests/test_audit_project.py +202 -0
  44. docpull-6.10.0/tests/test_audit_runtime.py +309 -0
  45. {docpull-6.8.0 → docpull-6.10.0}/tests/test_compat_jobs.py +1 -1
  46. {docpull-6.8.0 → docpull-6.10.0}/tests/test_reproducible_release_build.py +0 -12
  47. docpull-6.10.0/tests/test_sitemap_lastmod_skip.py +337 -0
  48. docpull-6.8.0/tests/test_ci_policy.py +0 -378
  49. docpull-6.8.0/tests/test_claim_audit_script.py +0 -74
  50. docpull-6.8.0/tests/test_release_a_plus_check_script.py +0 -149
  51. {docpull-6.8.0 → docpull-6.10.0}/LICENSE +0 -0
  52. {docpull-6.8.0 → docpull-6.10.0}/README.md +0 -0
  53. {docpull-6.8.0 → docpull-6.10.0}/setup.cfg +0 -0
  54. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/__main__.py +0 -0
  55. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/_jsonutil.py +0 -0
  56. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/accounting.py +0 -0
  57. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/acquisition_workflows.py +0 -0
  58. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/agent_publish.py +0 -0
  59. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/auth_cli.py +0 -0
  60. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/cache/__init__.py +0 -0
  61. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/cache/frontier.py +0 -0
  62. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/cache/streaming_dedup.py +0 -0
  63. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/compat_api.py +0 -0
  64. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_aliases.py +0 -0
  65. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/__init__.py +0 -0
  66. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/_legacy_cli.py +0 -0
  67. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/brand.py +0 -0
  68. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/common.py +0 -0
  69. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/dataset.py +0 -0
  70. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/feed.py +0 -0
  71. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/openapi.py +0 -0
  72. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/package.py +0 -0
  73. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/paper.py +0 -0
  74. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/policy_pack.py +0 -0
  75. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/product.py +0 -0
  76. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/relationship.py +0 -0
  77. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/repo.py +0 -0
  78. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/standards.py +0 -0
  79. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/styleguide.py +0 -0
  80. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/transcript.py +0 -0
  81. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/typed.py +0 -0
  82. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/typed_models.py +0 -0
  83. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/visuals.py +0 -0
  84. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/website.py +0 -0
  85. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/wiki.py +0 -0
  86. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/context_packs/workflow_cli.py +0 -0
  87. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/contracts.py +0 -0
  88. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/contracts_cli.py +0 -0
  89. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/__init__.py +0 -0
  90. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/article_cleanup.py +0 -0
  91. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/chunking.py +0 -0
  92. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/ensemble.py +0 -0
  93. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/extractor.py +0 -0
  94. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/filings.py +0 -0
  95. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/markdown.py +0 -0
  96. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/protocols.py +0 -0
  97. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/special_cases.py +0 -0
  98. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/conversion/trafilatura_extractor.py +0 -0
  99. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/core/__init__.py +0 -0
  100. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/__init__.py +0 -0
  101. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/_fetch.py +0 -0
  102. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/crawler.py +0 -0
  103. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/filters.py +0 -0
  104. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/link_extractors/__init__.py +0 -0
  105. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/link_extractors/enhanced.py +0 -0
  106. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/link_extractors/protocols.py +0 -0
  107. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/link_extractors/static.py +0 -0
  108. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery/protocols.py +0 -0
  109. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/discovery_index.py +0 -0
  110. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/doctor.py +0 -0
  111. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/document_worker.py +0 -0
  112. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/evidence.py +0 -0
  113. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/export_formats.py +0 -0
  114. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/exports.py +0 -0
  115. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/fixtures/__init__.py +0 -0
  116. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/graph.py +0 -0
  117. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/http/__init__.py +0 -0
  118. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/http/protocols.py +0 -0
  119. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/integrations/__init__.py +0 -0
  120. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/integrations/_records.py +0 -0
  121. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/integrations/langchain.py +0 -0
  122. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/integrations/llamaindex.py +0 -0
  123. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/judge.py +0 -0
  124. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/local_workflows.py +0 -0
  125. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/mcp/__init__.py +0 -0
  126. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/mcp/sources.py +0 -0
  127. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/metadata_extractor.py +0 -0
  128. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/__init__.py +0 -0
  129. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/document.py +0 -0
  130. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/profiles.py +0 -0
  131. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/run.py +0 -0
  132. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/models/schema.py +0 -0
  133. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/__init__.py +0 -0
  134. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/base.py +0 -0
  135. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/__init__.py +0 -0
  136. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/chunk.py +0 -0
  137. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/convert.py +0 -0
  138. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/dedup.py +0 -0
  139. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/metadata.py +0 -0
  140. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/render.py +0 -0
  141. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/save_ndjson.py +0 -0
  142. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/save_okf.py +0 -0
  143. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/save_sqlite.py +0 -0
  144. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/screen.py +0 -0
  145. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/pipeline/steps/validate.py +0 -0
  146. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/policy.py +0 -0
  147. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/policy_cli.py +0 -0
  148. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/provenance.py +0 -0
  149. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/py.typed +0 -0
  150. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/registry.py +0 -0
  151. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/research.py +0 -0
  152. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/artifact-manifest.v1.schema.json +0 -0
  153. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/basis.v2.schema.json +0 -0
  154. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/change-event.v1.schema.json +0 -0
  155. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/citation-map.v1.schema.json +0 -0
  156. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/document.v3.schema.json +0 -0
  157. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/intelligence-bundle.v1.schema.json +0 -0
  158. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/pack.v3.schema.json +0 -0
  159. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/provenance.v1.schema.json +0 -0
  160. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/relationship-pack.v1.schema.json +0 -0
  161. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/rights.v1.schema.json +0 -0
  162. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/run-identity.v1.schema.json +0 -0
  163. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/website-snapshot.v1.schema.json +0 -0
  164. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/workflow-request.v1.schema.json +0 -0
  165. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/schemas/workflow-result.v1.schema.json +0 -0
  166. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/__init__.py +0 -0
  167. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/download_policy.py +0 -0
  168. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/injection.py +0 -0
  169. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/optout.py +0 -0
  170. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/robots.py +0 -0
  171. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/security/url_validator.py +0 -0
  172. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/share.py +0 -0
  173. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/source_scoring.py +0 -0
  174. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/time_utils.py +0 -0
  175. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/warc.py +0 -0
  176. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/web_search.py +0 -0
  177. {docpull-6.8.0 → docpull-6.10.0}/src/docpull/workflows.py +0 -0
  178. {docpull-6.8.0 → docpull-6.10.0}/src/docpull.egg-info/dependency_links.txt +0 -0
  179. {docpull-6.8.0 → docpull-6.10.0}/src/docpull.egg-info/entry_points.txt +0 -0
  180. {docpull-6.8.0 → docpull-6.10.0}/src/docpull.egg-info/requires.txt +0 -0
  181. {docpull-6.8.0 → docpull-6.10.0}/src/docpull.egg-info/top_level.txt +0 -0
  182. {docpull-6.8.0 → docpull-6.10.0}/tests/test_accounting.py +0 -0
  183. {docpull-6.8.0 → docpull-6.10.0}/tests/test_acquisition_workflows.py +0 -0
  184. {docpull-6.8.0 → docpull-6.10.0}/tests/test_auth_cli.py +0 -0
  185. {docpull-6.8.0 → docpull-6.10.0}/tests/test_basis.py +0 -0
  186. {docpull-6.8.0 → docpull-6.10.0}/tests/test_cache_conditional_get.py +0 -0
  187. {docpull-6.8.0 → docpull-6.10.0}/tests/test_cache_lock_regressions.py +0 -0
  188. {docpull-6.8.0 → docpull-6.10.0}/tests/test_chunking.py +0 -0
  189. {docpull-6.8.0 → docpull-6.10.0}/tests/test_cli.py +0 -0
  190. {docpull-6.8.0 → docpull-6.10.0}/tests/test_compat_api.py +0 -0
  191. {docpull-6.8.0 → docpull-6.10.0}/tests/test_context_ci.py +0 -0
  192. {docpull-6.8.0 → docpull-6.10.0}/tests/test_context_packs.py +0 -0
  193. {docpull-6.8.0 → docpull-6.10.0}/tests/test_context_query.py +0 -0
  194. {docpull-6.8.0 → docpull-6.10.0}/tests/test_conversion.py +0 -0
  195. {docpull-6.8.0 → docpull-6.10.0}/tests/test_convert_step_new.py +0 -0
  196. {docpull-6.8.0 → docpull-6.10.0}/tests/test_crawl_regressions.py +0 -0
  197. {docpull-6.8.0 → docpull-6.10.0}/tests/test_discovery.py +0 -0
  198. {docpull-6.8.0 → docpull-6.10.0}/tests/test_discovery_index.py +0 -0
  199. {docpull-6.8.0 → docpull-6.10.0}/tests/test_doctor.py +0 -0
  200. {docpull-6.8.0 → docpull-6.10.0}/tests/test_document_parse.py +0 -0
  201. {docpull-6.8.0 → docpull-6.10.0}/tests/test_document_record.py +0 -0
  202. {docpull-6.8.0 → docpull-6.10.0}/tests/test_exports.py +0 -0
  203. {docpull-6.8.0 → docpull-6.10.0}/tests/test_extractor_ensemble.py +0 -0
  204. {docpull-6.8.0 → docpull-6.10.0}/tests/test_feed_pack.py +0 -0
  205. {docpull-6.8.0 → docpull-6.10.0}/tests/test_fetch_lifecycle.py +0 -0
  206. {docpull-6.8.0 → docpull-6.10.0}/tests/test_frontier_resume.py +0 -0
  207. {docpull-6.8.0 → docpull-6.10.0}/tests/test_frozen.py +0 -0
  208. {docpull-6.8.0 → docpull-6.10.0}/tests/test_graph.py +0 -0
  209. {docpull-6.8.0 → docpull-6.10.0}/tests/test_http_efficiency.py +0 -0
  210. {docpull-6.8.0 → docpull-6.10.0}/tests/test_import_efficiency.py +0 -0
  211. {docpull-6.8.0 → docpull-6.10.0}/tests/test_injection_screen.py +0 -0
  212. {docpull-6.8.0 → docpull-6.10.0}/tests/test_integration.py +0 -0
  213. {docpull-6.8.0 → docpull-6.10.0}/tests/test_integrations.py +0 -0
  214. {docpull-6.8.0 → docpull-6.10.0}/tests/test_jsonutil.py +0 -0
  215. {docpull-6.8.0 → docpull-6.10.0}/tests/test_judge.py +0 -0
  216. {docpull-6.8.0 → docpull-6.10.0}/tests/test_link_extractors.py +0 -0
  217. {docpull-6.8.0 → docpull-6.10.0}/tests/test_live_web_smoke.py +0 -0
  218. {docpull-6.8.0 → docpull-6.10.0}/tests/test_local_pack_workflows.py +0 -0
  219. {docpull-6.8.0 → docpull-6.10.0}/tests/test_local_workflows.py +0 -0
  220. {docpull-6.8.0 → docpull-6.10.0}/tests/test_mcp_server.py +0 -0
  221. {docpull-6.8.0 → docpull-6.10.0}/tests/test_mcp_tools.py +0 -0
  222. {docpull-6.8.0 → docpull-6.10.0}/tests/test_metadata_extractor.py +0 -0
  223. {docpull-6.8.0 → docpull-6.10.0}/tests/test_model_cache_lock.py +0 -0
  224. {docpull-6.8.0 → docpull-6.10.0}/tests/test_model_crawl_politeness.py +0 -0
  225. {docpull-6.8.0 → docpull-6.10.0}/tests/test_model_fetch_pipeline.py +0 -0
  226. {docpull-6.8.0 → docpull-6.10.0}/tests/test_model_jobs_monitor.py +0 -0
  227. {docpull-6.8.0 → docpull-6.10.0}/tests/test_monitor.py +0 -0
  228. {docpull-6.8.0 → docpull-6.10.0}/tests/test_monitor_fetch_failures.py +0 -0
  229. {docpull-6.8.0 → docpull-6.10.0}/tests/test_naming.py +0 -0
  230. {docpull-6.8.0 → docpull-6.10.0}/tests/test_openapi_pack.py +0 -0
  231. {docpull-6.8.0 → docpull-6.10.0}/tests/test_optional_extras_installed.py +0 -0
  232. {docpull-6.8.0 → docpull-6.10.0}/tests/test_optout.py +0 -0
  233. {docpull-6.8.0 → docpull-6.10.0}/tests/test_output_contract.py +0 -0
  234. {docpull-6.8.0 → docpull-6.10.0}/tests/test_outputs_e2e.py +0 -0
  235. {docpull-6.8.0 → docpull-6.10.0}/tests/test_pack_server.py +0 -0
  236. {docpull-6.8.0 → docpull-6.10.0}/tests/test_pack_tools.py +0 -0
  237. {docpull-6.8.0 → docpull-6.10.0}/tests/test_parser_dependency_support.py +0 -0
  238. {docpull-6.8.0 → docpull-6.10.0}/tests/test_pipeline.py +0 -0
  239. {docpull-6.8.0 → docpull-6.10.0}/tests/test_policy.py +0 -0
  240. {docpull-6.8.0 → docpull-6.10.0}/tests/test_policy_cli.py +0 -0
  241. {docpull-6.8.0 → docpull-6.10.0}/tests/test_project.py +0 -0
  242. {docpull-6.8.0 → docpull-6.10.0}/tests/test_provenance.py +0 -0
  243. {docpull-6.8.0 → docpull-6.10.0}/tests/test_public_feature_smoke.py +0 -0
  244. {docpull-6.8.0 → docpull-6.10.0}/tests/test_qa_judge.py +0 -0
  245. {docpull-6.8.0 → docpull-6.10.0}/tests/test_rate_limiter.py +0 -0
  246. {docpull-6.8.0 → docpull-6.10.0}/tests/test_real_feature_smoke_script.py +0 -0
  247. {docpull-6.8.0 → docpull-6.10.0}/tests/test_real_site_regressions.py +0 -0
  248. {docpull-6.8.0 → docpull-6.10.0}/tests/test_registry.py +0 -0
  249. {docpull-6.8.0 → docpull-6.10.0}/tests/test_relationship_workflow.py +0 -0
  250. {docpull-6.8.0 → docpull-6.10.0}/tests/test_release_registry_workflows.py +0 -0
  251. {docpull-6.8.0 → docpull-6.10.0}/tests/test_rendering.py +0 -0
  252. {docpull-6.8.0 → docpull-6.10.0}/tests/test_research.py +0 -0
  253. {docpull-6.8.0 → docpull-6.10.0}/tests/test_save_ndjson.py +0 -0
  254. {docpull-6.8.0 → docpull-6.10.0}/tests/test_save_sqlite.py +0 -0
  255. {docpull-6.8.0 → docpull-6.10.0}/tests/test_security_hardening.py +0 -0
  256. {docpull-6.8.0 → docpull-6.10.0}/tests/test_share.py +0 -0
  257. {docpull-6.8.0 → docpull-6.10.0}/tests/test_source_scoring.py +0 -0
  258. {docpull-6.8.0 → docpull-6.10.0}/tests/test_special_cases.py +0 -0
  259. {docpull-6.8.0 → docpull-6.10.0}/tests/test_surface_contract.py +0 -0
  260. {docpull-6.8.0 → docpull-6.10.0}/tests/test_time_utils.py +0 -0
  261. {docpull-6.8.0 → docpull-6.10.0}/tests/test_token_metrics.py +0 -0
  262. {docpull-6.8.0 → docpull-6.10.0}/tests/test_trafilatura_extractor.py +0 -0
  263. {docpull-6.8.0 → docpull-6.10.0}/tests/test_typed_knowledge_packs.py +0 -0
  264. {docpull-6.8.0 → docpull-6.10.0}/tests/test_warc.py +0 -0
  265. {docpull-6.8.0 → docpull-6.10.0}/tests/test_web_search.py +0 -0
  266. {docpull-6.8.0 → docpull-6.10.0}/tests/test_website_snapshot.py +0 -0
  267. {docpull-6.8.0 → docpull-6.10.0}/tests/test_workflow_contracts.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docpull
3
- Version: 6.8.0
3
+ Version: 6.10.0
4
4
  Summary: Declare, sync, diff, and lock context dependencies for AI agents
5
5
  Author-email: Zachary Roth <support@raintree.technology>
6
6
  Maintainer-email: Raintree Technology <support@raintree.technology>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "docpull"
7
- version = "6.8.0"
7
+ version = "6.10.0"
8
8
  dynamic = []
9
9
  description = "Declare, sync, diff, and lock context dependencies for AI agents"
10
10
  readme = {file = "README.md", content-type = "text/markdown"}
@@ -207,6 +207,9 @@ include = ["docpull*"]
207
207
  docpull = ["py.typed", "fixtures/*.json", "schemas/*.schema.json"]
208
208
 
209
209
  [tool.uv]
210
+ # unstructured caps filelock below 4, which leaves the locked dev environment on
211
+ # a vulnerable release. Drop this once unstructured allows filelock 4.
212
+ override-dependencies = ["filelock>=4.2.1"]
210
213
  constraint-dependencies = [
211
214
  "h2>=4.4.1",
212
215
  "multidict>=6.9.1",
@@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Any
15
15
 
16
16
  from .surface import PUBLIC_SDK_EXPORTS
17
17
 
18
- __version__ = "6.8.0"
18
+ __version__ = "6.10.0"
19
19
 
20
20
  _LAZY_EXPORTS: dict[str, tuple[str, str]] = {
21
21
  "query_context": (".context_query", "query_context"),
@@ -0,0 +1,89 @@
1
+ """Small filesystem helpers: atomic text writes and advisory file locks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import os
7
+ import tempfile
8
+ from collections.abc import Iterator
9
+ from pathlib import Path
10
+ from typing import IO, Any
11
+
12
+ try: # POSIX
13
+ import fcntl as _fcntl
14
+ except ImportError: # pragma: no cover - Windows
15
+ _fcntl = None # type: ignore[assignment]
16
+
17
+ try: # Windows
18
+ import msvcrt as _msvcrt
19
+ except ImportError:
20
+ _msvcrt = None # type: ignore[assignment]
21
+
22
+
23
+ def atomic_write_text(path: Path | str, text: str, *, encoding: str = "utf-8") -> None:
24
+ """Write ``text`` to ``path`` via a unique temp file in the same dir + ``os.replace``.
25
+
26
+ Each writer gets its own temp file, so concurrent writers never clobber
27
+ each other's half-written temp; the last ``os.replace`` wins atomically.
28
+ """
29
+ target = Path(path)
30
+ target.parent.mkdir(parents=True, exist_ok=True)
31
+ tmp_name: str | None = None
32
+ try:
33
+ with tempfile.NamedTemporaryFile(
34
+ "w",
35
+ encoding=encoding,
36
+ dir=target.parent,
37
+ prefix=f".{target.name}.",
38
+ suffix=".tmp",
39
+ delete=False,
40
+ ) as handle:
41
+ tmp_name = handle.name
42
+ handle.write(text)
43
+ handle.flush()
44
+ os.fsync(handle.fileno())
45
+ os.replace(tmp_name, target)
46
+ except BaseException:
47
+ if tmp_name is not None:
48
+ with contextlib.suppress(OSError):
49
+ os.unlink(tmp_name)
50
+ raise
51
+
52
+
53
+ def _lock(handle: IO[Any]) -> None:
54
+ if _fcntl is not None:
55
+ _fcntl.flock(handle.fileno(), _fcntl.LOCK_EX)
56
+ elif _msvcrt is not None: # pragma: no cover - Windows
57
+ handle.seek(0)
58
+ while True:
59
+ try:
60
+ _msvcrt.locking(handle.fileno(), _msvcrt.LK_LOCK, 1)
61
+ return
62
+ except OSError:
63
+ continue
64
+
65
+
66
+ def _unlock(handle: IO[Any]) -> None:
67
+ if _fcntl is not None:
68
+ _fcntl.flock(handle.fileno(), _fcntl.LOCK_UN)
69
+ elif _msvcrt is not None: # pragma: no cover - Windows
70
+ handle.seek(0)
71
+ with contextlib.suppress(OSError):
72
+ _msvcrt.locking(handle.fileno(), _msvcrt.LK_UNLCK, 1)
73
+
74
+
75
+ @contextlib.contextmanager
76
+ def file_lock(path: Path | str) -> Iterator[None]:
77
+ """Exclusive advisory lock on ``path`` (created if missing), blocking.
78
+
79
+ Uses ``fcntl.flock`` on POSIX and ``msvcrt.locking`` on Windows; a no-op
80
+ where neither exists. Advisory only: cooperating writers must all use it.
81
+ """
82
+ lock_path = Path(path)
83
+ lock_path.parent.mkdir(parents=True, exist_ok=True)
84
+ with open(lock_path, "a+b") as handle:
85
+ _lock(handle)
86
+ try:
87
+ yield
88
+ finally:
89
+ _unlock(handle)
@@ -1,4 +1,11 @@
1
- """Shared local evidence basis records."""
1
+ """Evidence basis records: which cited sources support each claim in a pack.
2
+
3
+ A basis record ties one claim path to citation IDs, source URLs, and excerpts,
4
+ with a confidence and an evidence state (supported, partial, insufficient). This
5
+ module builds and normalizes those records, writes and reads ``basis.ndjson``,
6
+ and summarizes them into ``basis.report.json`` and Markdown for eval-grade packs
7
+ and context CI. It is local and offline; "basis" means evidentiary basis.
8
+ """
2
9
 
3
10
  from __future__ import annotations
4
11
 
@@ -5,11 +5,14 @@ from __future__ import annotations
5
5
  import hashlib
6
6
  import json
7
7
  import logging
8
+ import os
8
9
  import tempfile
10
+ import time
9
11
  from datetime import timedelta
10
12
  from pathlib import Path
11
13
  from typing import Any, TypedDict
12
14
 
15
+ from .._fileutil import file_lock
13
16
  from ..time_utils import parse_persisted_datetime, utc_now, utc_now_iso
14
17
  from .frontier import FrontierStore
15
18
 
@@ -28,6 +31,8 @@ class ManifestEntry(TypedDict, total=False):
28
31
  size: int
29
32
  etag: str
30
33
  last_modified: str
34
+ sitemap_lastmod: str
35
+ verified_at: str
31
36
  schema_version: int
32
37
  run_fingerprint: dict[str, Any]
33
38
 
@@ -110,12 +115,31 @@ class CacheManager:
110
115
  self.frontier_file = self.cache_dir / "frontier.json"
111
116
  self.frontier = FrontierStore(self.frontier_file)
112
117
 
118
+ self.lock_file = self.cache_dir / ".cache.lock"
119
+
113
120
  self.manifest: dict[str, ManifestEntry] = self._load_manifest()
114
121
  self._state: _InternalState = _InternalState.from_cache_state(self._load_state())
115
122
 
116
123
  # Track if there are unsaved changes (for batched writes)
117
124
  self._manifest_dirty = False
118
125
  self._state_dirty = False
126
+ # Per-URL deltas since the last flush. flush() re-reads the on-disk
127
+ # files under an advisory lock and applies only these deltas, so
128
+ # concurrent processes sharing a cache dir don't drop each other's
129
+ # entries (last writer no longer wins wholesale).
130
+ self._touched: set[str] = set()
131
+ self._removed: set[str] = set()
132
+ self._state_ops: dict[str, str] = {}
133
+ self._last_run_set = False
134
+
135
+ def _backup_corrupt(self, path: Path, err: Exception) -> None:
136
+ """Move an unreadable cache file aside instead of silently losing it."""
137
+ backup = path.with_name(f"{path.name}.corrupt-{time.strftime('%Y%m%dT%H%M%S')}-{os.getpid()}")
138
+ try:
139
+ os.replace(path, backup)
140
+ logger.warning("Could not load %s (%s); moved it to %s and starting empty", path, err, backup)
141
+ except OSError as move_err:
142
+ logger.warning("Could not load %s (%s); backup to %s failed: %s", path, err, backup, move_err)
119
143
 
120
144
  def _load_manifest(self) -> dict[str, ManifestEntry]:
121
145
  """Load manifest from disk.
@@ -136,7 +160,15 @@ class CacheManager:
136
160
  logger.warning("Skipping invalid cache manifest entry for %r", url)
137
161
  continue
138
162
  entry: ManifestEntry = {}
139
- for key in ("checksum", "file_path", "fetched_at", "etag", "last_modified"):
163
+ for key in (
164
+ "checksum",
165
+ "file_path",
166
+ "fetched_at",
167
+ "etag",
168
+ "last_modified",
169
+ "sitemap_lastmod",
170
+ "verified_at",
171
+ ):
140
172
  value = raw_entry.get(key)
141
173
  if isinstance(value, str):
142
174
  entry[key] = value # type: ignore[literal-required]
@@ -152,7 +184,7 @@ class CacheManager:
152
184
  manifest[url] = entry
153
185
  return manifest
154
186
  except Exception as e:
155
- logger.warning(f"Could not load manifest: {e}")
187
+ self._backup_corrupt(self.manifest_file, e)
156
188
 
157
189
  return {}
158
190
 
@@ -178,14 +210,24 @@ class CacheManager:
178
210
  raise
179
211
 
180
212
  def _save_manifest(self) -> None:
181
- """Save manifest to disk (internal, called by flush)."""
213
+ """Merge this process's manifest deltas into the on-disk manifest.
214
+
215
+ Called by flush() with the cache lock held. Write errors propagate.
216
+ """
182
217
  if not self._manifest_dirty:
183
218
  return
184
- try:
185
- self._write_json(self.manifest_file, self.manifest)
186
- self._manifest_dirty = False
187
- except Exception as e:
188
- logger.error(f"Could not save manifest: {e}")
219
+ merged = self._load_manifest()
220
+ for url in self._removed:
221
+ merged.pop(url, None)
222
+ for url in self._touched:
223
+ entry = self.manifest.get(url)
224
+ if entry is not None:
225
+ merged[url] = entry
226
+ self._write_json(self.manifest_file, merged)
227
+ self.manifest = merged
228
+ self._touched.clear()
229
+ self._removed.clear()
230
+ self._manifest_dirty = False
189
231
 
190
232
  def _load_state(self) -> CacheState:
191
233
  """Load state from disk.
@@ -207,7 +249,7 @@ class CacheManager:
207
249
  "last_run": last_run if isinstance(last_run, str) else None,
208
250
  }
209
251
  except Exception as e:
210
- logger.warning(f"Could not load state: {e}")
252
+ self._backup_corrupt(self.state_file, e)
211
253
 
212
254
  return {
213
255
  "fetched_urls": [],
@@ -219,21 +261,40 @@ class CacheManager:
219
261
  """Save state to disk (internal, called by flush)."""
220
262
  if not self._state_dirty:
221
263
  return
222
- try:
223
- state = self._state.to_cache_state()
224
- self._write_json(self.state_file, state)
225
- self._state_dirty = False
226
- except Exception as e:
227
- logger.error(f"Could not save state: {e}")
264
+ merged = _InternalState.from_cache_state(self._load_state())
265
+ for url, op in self._state_ops.items():
266
+ merged.fetched_urls.discard(url)
267
+ merged.failed_urls.discard(url)
268
+ if op == "fetched":
269
+ merged.fetched_urls.add(url)
270
+ elif op == "failed":
271
+ merged.failed_urls.add(url)
272
+ if self._last_run_set:
273
+ merged.last_run = self._state.last_run
274
+ self._write_json(self.state_file, merged.to_cache_state())
275
+ self._state = merged
276
+ self._state_ops.clear()
277
+ self._last_run_set = False
278
+ self._state_dirty = False
228
279
 
229
280
  def flush(self) -> None:
230
281
  """Flush all pending changes to disk.
231
282
 
232
283
  Call this after a batch of operations to persist changes.
233
284
  This is more efficient than saving after every operation.
285
+
286
+ Holds an advisory lock on ``.cache.lock`` and merges with what is on
287
+ disk, so concurrent processes sharing the cache dir keep each
288
+ other's entries. Write failures raise (they are not swallowed).
289
+
290
+ Ordering: the manifest is written before state. If the process dies
291
+ between the two, state is merely behind the manifest, which only
292
+ means some URLs are re-fetched (conditional GET) on resume. The
293
+ reverse order could mark a URL fetched with no manifest entry.
234
294
  """
235
- self._save_manifest()
236
- self._save_state()
295
+ with file_lock(self.lock_file):
296
+ self._save_manifest()
297
+ self._save_state()
237
298
  self.frontier.flush()
238
299
 
239
300
  def __enter__(self) -> CacheManager:
@@ -247,7 +308,14 @@ class CacheManager:
247
308
  exc_tb: object | None,
248
309
  ) -> None:
249
310
  """Context manager exit - auto-flush on exit."""
250
- self.flush()
311
+ if exc_type is None:
312
+ self.flush()
313
+ return
314
+ # Don't mask the in-flight exception with a flush failure.
315
+ try:
316
+ self.flush()
317
+ except Exception:
318
+ logger.exception("Could not flush cache in %s", self.cache_dir)
251
319
 
252
320
  @staticmethod
253
321
  def compute_checksum(content: str | bytes) -> str:
@@ -277,6 +345,7 @@ class CacheManager:
277
345
  etag: str | None = None,
278
346
  last_modified: str | None = None,
279
347
  run_fingerprint: dict[str, Any] | None = None,
348
+ sitemap_lastmod: str | None = None,
280
349
  ) -> None:
281
350
  """Update cache entry for a URL.
282
351
 
@@ -286,6 +355,7 @@ class CacheManager:
286
355
  file_path: Path where content was saved
287
356
  etag: HTTP ETag header
288
357
  last_modified: HTTP Last-Modified header
358
+ sitemap_lastmod: Normalized sitemap ``<lastmod>`` seen for this URL
289
359
 
290
360
  Note:
291
361
  Changes are batched. Call flush() to persist to disk.
@@ -304,8 +374,34 @@ class CacheManager:
304
374
  self.manifest[url]["etag"] = etag
305
375
  if last_modified:
306
376
  self.manifest[url]["last_modified"] = last_modified
377
+ if sitemap_lastmod:
378
+ self.manifest[url]["sitemap_lastmod"] = sitemap_lastmod
379
+
380
+ self._touched.add(url)
381
+ self._removed.discard(url)
382
+ self._manifest_dirty = True
383
+
384
+ def mark_verified(self, url: str, sitemap_lastmod: str | None = None) -> None:
385
+ """Record that the server just confirmed a cached page is still current."""
386
+ entry = self.manifest.get(url)
387
+ if entry is None:
388
+ return
389
+ entry["verified_at"] = utc_now_iso()
390
+ if sitemap_lastmod:
391
+ entry["sitemap_lastmod"] = sitemap_lastmod
392
+ self._touched.add(url)
393
+ self._manifest_dirty = True
307
394
 
395
+ def forget(self, url: str) -> None:
396
+ """Drop a URL from the manifest and state."""
397
+ self.manifest.pop(url, None)
398
+ self._state.fetched_urls.discard(url)
399
+ self._state.failed_urls.discard(url)
400
+ self._touched.discard(url)
401
+ self._removed.add(url)
402
+ self._state_ops[url] = "forget"
308
403
  self._manifest_dirty = True
404
+ self._state_dirty = True
309
405
 
310
406
  def mark_fetched(self, url: str) -> None:
311
407
  """Mark URL as successfully fetched.
@@ -318,6 +414,7 @@ class CacheManager:
318
414
  """
319
415
  self._state.fetched_urls.add(url)
320
416
  self._state.failed_urls.discard(url)
417
+ self._state_ops[url] = "fetched"
321
418
  self.frontier.mark_succeeded(url)
322
419
  self._state_dirty = True
323
420
 
@@ -332,6 +429,7 @@ class CacheManager:
332
429
  """
333
430
  self._state.failed_urls.add(url)
334
431
  self._state.fetched_urls.discard(url)
432
+ self._state_ops[url] = "failed"
335
433
  self.frontier.mark_failed(url)
336
434
  self._state_dirty = True
337
435
 
@@ -350,6 +448,7 @@ class CacheManager:
350
448
  Changes are batched. Call flush() to persist to disk.
351
449
  """
352
450
  self._state.last_run = utc_now_iso()
451
+ self._last_run_set = True
353
452
  self._state_dirty = True
354
453
 
355
454
  def evict_expired(self, ttl_days: int | None = None) -> int:
@@ -369,10 +468,10 @@ class CacheManager:
369
468
  to_remove = []
370
469
 
371
470
  for url, entry in self.manifest.items():
372
- fetched_at = entry.get("fetched_at")
373
- if fetched_at:
471
+ checked_at = entry.get("verified_at") or entry.get("fetched_at")
472
+ if checked_at:
374
473
  try:
375
- entry_time = parse_persisted_datetime(fetched_at)
474
+ entry_time = parse_persisted_datetime(checked_at)
376
475
  if entry_time < cutoff:
377
476
  to_remove.append(url)
378
477
  except ValueError as err:
@@ -385,6 +484,9 @@ class CacheManager:
385
484
  for url in to_remove:
386
485
  self._state.fetched_urls.discard(url)
387
486
  self._state.failed_urls.discard(url)
487
+ self._touched.discard(url)
488
+ self._removed.add(url)
489
+ self._state_ops[url] = "forget"
388
490
  self._manifest_dirty = True
389
491
  self._state_dirty = True
390
492
  logger.info(f"Evicted {len(to_remove)} expired cache entries")
@@ -423,11 +525,10 @@ class CacheManager:
423
525
  self.frontier.initialize(start_url=start_url, run_fingerprint=config_fingerprint)
424
526
  self.frontier.add_many(urls, source="discovery")
425
527
  self.frontier.save()
426
- try:
427
- self._write_json(self.discovered_urls_file, data)
428
- logger.info(f"Saved {len(urls)} discovered URLs for resume capability")
429
- except Exception as e:
430
- logger.error(f"Could not save discovered URLs: {e}")
528
+ # Write errors propagate: a silently missing resume snapshot would
529
+ # make --resume restart from scratch without telling anyone.
530
+ self._write_json(self.discovered_urls_file, data)
531
+ logger.info(f"Saved {len(urls)} discovered URLs for resume capability")
431
532
 
432
533
  def load_discovered_urls(
433
534
  self,
@@ -465,7 +566,7 @@ class CacheManager:
465
566
  logger.info(f"Loaded {len(urls)} discovered URLs from previous run")
466
567
  return urls
467
568
  except Exception as e:
468
- logger.warning(f"Could not load discovered URLs: {e}")
569
+ self._backup_corrupt(self.discovered_urls_file, e)
469
570
  return None
470
571
 
471
572
  def get_pending_urls(
@@ -7,6 +7,7 @@ import json
7
7
  from pathlib import Path
8
8
  from typing import Any, Literal
9
9
 
10
+ from ._fileutil import atomic_write_text
10
11
  from .contracts import ChangeEvent, ReplayConfiguration, canonical_sha256, stable_id
11
12
  from .evidence import evidence_span
12
13
 
@@ -41,7 +42,9 @@ def build_change_events(
41
42
  new_primary = new_items[0] if new_items else None
42
43
  old_text = _combined_content(old_items)
43
44
  new_text = _combined_content(new_items)
44
- classifications = _classifications(old_text, new_text, url)
45
+ # One lowercase haystack per event, shared by classification and confidence.
46
+ haystack = f"{url}\n{old_text}\n{new_text}".lower()
47
+ classifications = _classifications(haystack)
45
48
  structural = _structural_changes(old_items, new_items)
46
49
  textual = _textual_changes(old_text, new_text)
47
50
  old_evidence = _record_evidence(old_primary, old_text) if old_primary else []
@@ -57,7 +60,7 @@ def build_change_events(
57
60
  {
58
61
  "classification": item,
59
62
  "status": "candidate",
60
- "confidence": _classification_confidence(item, old_text, new_text, url),
63
+ "confidence": _classification_confidence(item, haystack),
61
64
  "requires_review": True,
62
65
  }
63
66
  for item in classifications
@@ -90,10 +93,9 @@ def build_change_events(
90
93
 
91
94
 
92
95
  def write_change_events(path: Path, events: list[dict[str, Any]]) -> Path:
93
- path.parent.mkdir(parents=True, exist_ok=True)
94
- path.write_text(
96
+ atomic_write_text(
97
+ path,
95
98
  "".join(json.dumps(event, ensure_ascii=False, sort_keys=True) + "\n" for event in events),
96
- encoding="utf-8",
97
99
  )
98
100
  return path
99
101
 
@@ -140,9 +142,8 @@ def _structural_changes(
140
142
  def _textual_changes(old_text: str, new_text: str) -> list[dict[str, Any]]:
141
143
  old_lines = old_text.splitlines()
142
144
  new_lines = new_text.splitlines()
143
- matcher = difflib.SequenceMatcher(a=old_lines, b=new_lines, autojunk=False)
144
145
  changes: list[dict[str, Any]] = []
145
- for tag, i1, i2, j1, j2 in matcher.get_opcodes():
146
+ for tag, i1, i2, j1, j2 in _line_opcodes(old_lines, new_lines):
146
147
  if tag == "equal":
147
148
  continue
148
149
  before = "\n".join(old_lines[i1:i2])[:1000]
@@ -165,8 +166,44 @@ def _textual_changes(old_text: str, new_text: str) -> list[dict[str, Any]]:
165
166
  return changes
166
167
 
167
168
 
168
- def _classifications(old_text: str, new_text: str, url: str) -> list[ChangeClassification]:
169
- haystack = f"{url}\n{old_text}\n{new_text}".lower()
169
+ # SequenceMatcher(autojunk=False) is quadratic in line counts; above this many
170
+ # line-pair comparisons the diff falls back to a bounded prefix/suffix scan.
171
+ _MAX_DIFF_LINE_PRODUCT = 4_000_000
172
+
173
+
174
+ def _line_opcodes(old_lines: list[str], new_lines: list[str]) -> list[tuple[str, int, int, int, int]]:
175
+ if len(old_lines) * len(new_lines) <= _MAX_DIFF_LINE_PRODUCT:
176
+ matcher = difflib.SequenceMatcher(a=old_lines, b=new_lines, autojunk=False)
177
+ return list(matcher.get_opcodes())
178
+ # Large documents: trim the shared head and tail (linear), then diff the middle
179
+ # only if it is small enough, otherwise report it as one replaced block.
180
+ prefix = 0
181
+ limit = min(len(old_lines), len(new_lines))
182
+ while prefix < limit and old_lines[prefix] == new_lines[prefix]:
183
+ prefix += 1
184
+ suffix = 0
185
+ while (
186
+ suffix < limit - prefix
187
+ and old_lines[len(old_lines) - 1 - suffix] == new_lines[len(new_lines) - 1 - suffix]
188
+ ):
189
+ suffix += 1
190
+ old_end = len(old_lines) - suffix
191
+ new_end = len(new_lines) - suffix
192
+ old_mid = old_lines[prefix:old_end]
193
+ new_mid = new_lines[prefix:new_end]
194
+ if not old_mid and not new_mid:
195
+ return []
196
+ if old_mid and new_mid and len(old_mid) * len(new_mid) <= _MAX_DIFF_LINE_PRODUCT:
197
+ matcher = difflib.SequenceMatcher(a=old_mid, b=new_mid, autojunk=False)
198
+ return [
199
+ (tag, i1 + prefix, i2 + prefix, j1 + prefix, j2 + prefix)
200
+ for tag, i1, i2, j1, j2 in matcher.get_opcodes()
201
+ ]
202
+ tag = "replace" if old_mid and new_mid else ("delete" if old_mid else "insert")
203
+ return [(tag, prefix, old_end, prefix, new_end)]
204
+
205
+
206
+ def _classifications(haystack: str) -> list[ChangeClassification]:
170
207
  output = [
171
208
  classification
172
209
  for classification, terms in _CLASSIFICATION_TERMS.items()
@@ -175,14 +212,8 @@ def _classifications(old_text: str, new_text: str, url: str) -> list[ChangeClass
175
212
  return output or ["other"]
176
213
 
177
214
 
178
- def _classification_confidence(
179
- classification: ChangeClassification,
180
- old_text: str,
181
- new_text: str,
182
- url: str,
183
- ) -> float:
215
+ def _classification_confidence(classification: ChangeClassification, haystack: str) -> float:
184
216
  terms = _CLASSIFICATION_TERMS.get(classification, ())
185
- haystack = f"{url}\n{old_text}\n{new_text}".lower()
186
217
  hits = sum(1 for term in terms if term in haystack)
187
218
  return min(0.95, 0.5 + hits * 0.1) if terms else 0.4
188
219