bindery-cli 0.61.0__tar.gz → 0.62.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 (56) hide show
  1. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/PKG-INFO +1 -1
  2. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/patchnotes.md +109 -0
  3. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/pyproject.toml +1 -1
  4. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/roadmap.md +2 -0
  5. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/__init__.py +1 -1
  6. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/cli.py +77 -0
  7. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/epub.py +351 -3
  8. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/transforms.py +30 -10
  9. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_cli.py +53 -7
  10. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_epub.py +525 -11
  11. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_flags_real_core.py +85 -0
  12. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_flags_wiring.py +4 -0
  13. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_transforms.py +74 -2
  14. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/uv.lock +1 -1
  15. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/.github/FUNDING.yml +0 -0
  16. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/.github/workflows/ci.yml +0 -0
  17. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/.github/workflows/publish.yml +0 -0
  18. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/.gitignore +0 -0
  19. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/AGENTS.md +0 -0
  20. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/LICENSE +0 -0
  21. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/OBSERVE-RESEARCH.md +0 -0
  22. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/README.md +0 -0
  23. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/docs/screenshots/library-sweep.png +0 -0
  24. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/logo.svg +0 -0
  25. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/plugin/__init__.py +0 -0
  26. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/project.done +0 -0
  27. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/run_tests.sh +0 -0
  28. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/scripts/FastSweep.java +0 -0
  29. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/scripts/build_plugin.py +0 -0
  30. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/scripts/fast_sweep.py +0 -0
  31. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/spec.md +0 -0
  32. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/__main__.py +0 -0
  33. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/audit.py +0 -0
  34. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/library.py +0 -0
  35. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/observe.py +0 -0
  36. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/pagination.py +0 -0
  37. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/reserialize.py +0 -0
  38. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/validate.py +0 -0
  39. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/src/bindery/watermark.py +0 -0
  40. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_audit.py +0 -0
  41. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_comment_hyphens.py +0 -0
  42. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_contamination.py +0 -0
  43. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_cover_tocdrift.py +0 -0
  44. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_help.py +0 -0
  45. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_library.py +0 -0
  46. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_matcher_hardening.py +0 -0
  47. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_observe.py +0 -0
  48. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_pagination.py +0 -0
  49. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_plugin.py +0 -0
  50. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_reserialize.py +0 -0
  51. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_space_renames.py +0 -0
  52. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_spine_guard.py +0 -0
  53. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_validate.py +0 -0
  54. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_version.py +0 -0
  55. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_watermark.py +0 -0
  56. {bindery_cli-0.61.0 → bindery_cli-0.62.0}/tests/test_xml_hardening.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bindery-cli
3
- Version: 0.61.0
3
+ Version: 0.62.0
4
4
  Summary: Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library.
5
5
  Project-URL: Homepage, https://github.com/VirInvictus/bindery-cli
6
6
  Project-URL: Repository, https://github.com/VirInvictus/bindery-cli
@@ -1,5 +1,114 @@
1
1
  # bindery-cli Patch Notes
2
2
 
3
+ ## v0.62.0 (2026-11-03)
4
+
5
+ ### The observatory batch: three predicate repairs and four new flags
6
+
7
+ The 2026-11-03 whole-library observatory run answered the default pass's
8
+ `0/0/0` (nothing applies, nothing rejects) with two discoveries: twelve
9
+ census codes had never been triaged, and the full `--all` arsenal's 322
10
+ rejections were 283 bundles poisoned by two transforms whose firing
11
+ predicates outran what epubcheck actually polices. This release carries the
12
+ batch that came out of it, every piece verified against epubcheck 5.3 on
13
+ real specimens or minimal matrices before the code moved.
14
+
15
+ **The three predicate repairs** (the playOrder precedent repeating):
16
+
17
+ - `fix_ncx_playorder`'s contract demanded values 1..K; the oracle polices
18
+ sharing, distinctness, and gaps and never the base (Age of Innocence
19
+ validates clean at 0..43; singleton-2, pair-2-3, and offset-5-8 verified).
20
+ The clause is base-free contiguous now, silencing the 107 no-op
21
+ renumberings the observatory measured while keeping every real fix.
22
+ - `fix_pagelist_class` inserts the collision-checked id alongside the
23
+ class: class-only insertion flipped epubcheck into demanding the id on
24
+ the element that had just gained the class (Feel Free: bare pageList
25
+ validates clean, `class="pages"` alone draws RSC-005 'missing required
26
+ attribute "id"', id+class validates fully clean) -- the 215-rejection
27
+ poison. The books that used to regress now measure flat; the ones that
28
+ used to accept still do.
29
+ - `fix_missing_title` fills the self-closed `<title/>`: the paired-fill
30
+ branch was unreachable dead code behind the no-op check, so every
31
+ self-closed shape fell through to injection beside the standing tag
32
+ (the 70-rejection poison; 84 sampled reject docs, all exactly
33
+ `<title/>`, each gaining RSC-005 'element "title" not allowed here').
34
+
35
+ **The four new flags** (the never-triaged census lanes):
36
+
37
+ - `--fix-package-version` (OPF-001, 26 books): rewrites the literal
38
+ `version="1.0"` on the package element to `"2.0"` -- an EPUB version
39
+ epubcheck cannot parse. Refuses everything else: the OEB-1.0-namespace
40
+ package with no version attribute is the designed refusal, and any other
41
+ spelling would be a guess about the producer's intent. Audition
42
+ validates fully clean after the bump.
43
+ - `--fix-doctype` (HTM-004, 135 books): replaces a content document's
44
+ DOCTYPE when it carries a public identifier its package profile forbids
45
+ -- EPUB 3 requires any DOCTYPE to be `<!DOCTYPE html>` (an XHTML 1.x
46
+ public doctype is a spec violation), and EPUB 2's OPS content docs are
47
+ XHTML 1.1 (the Hound-of-the-Baskervilles shape: found 1.0 Strict,
48
+ expected 1.1). Both census shapes verified on facility copies. The
49
+ first build also inserted a DOCTYPE when absent; the whole-library
50
+ firing census measured that flat on ~2,400 of 2,545 firing books -- an
51
+ absent DOCTYPE is legal in both profiles and the oracle tolerates it --
52
+ so insertion was removed before release: the flag fires only where the
53
+ declaration exists and is wrong. A whitespace-variant of the expected
54
+ form is a no-op, and a DOCTYPE carrying an internal subset is never
55
+ touched (the subset declares entities).
56
+ - `--prune-invalid-guide-refs` (OPF-032, 125 books): removes guide
57
+ `<reference>` elements whose target is declared but is not an OPS
58
+ content document -- the Random House `msr` guide block pointing
59
+ cover/thumbimage references at JPEGs is the dominant fingerprint. The
60
+ guide is furniture, so removal is content-neutral; a reference to an
61
+ undeclared file stays OPF-031 (declare-missing's lane), as do external
62
+ schemes and paired elements. Widdershins validates fully clean after
63
+ the prune.
64
+ - `--fix-item-properties` (OPF-014, 74 books): a whole-book census reads
65
+ what each content document contains and merges the tokens into the
66
+ owning manifest item's `properties` attribute, sorted and deduplicated.
67
+ `scripted` from a `<script>` element, an on* handler attribute, or a
68
+ `<form>` -- epubcheck 5.3 demands scripted for form documents, proven
69
+ by tag-off bisection on the Rustonomicon's scraped GitHub page; `svg`
70
+ from an `<svg>` element; `remote-resources` from an absolute-scheme src
71
+ attribute, a remote `<link href>`, or a remote CSS url(). EPUB 3
72
+ packages only: the matrix proved declaring `properties` on an EPUB2
73
+ item draws the illegal-attribute finding while its OPF-014 demand
74
+ stands, so the EPUB2 carriers refuse and stay measured. The census's
75
+ own lane specimen (Rustonomicon) cleared its OPF-014 live.
76
+
77
+ Suite: 878 tests.
78
+
79
+ ## v0.61.1 (2026-11-03)
80
+
81
+ ### The hex-ref href crash, and the sweep that survives it
82
+
83
+ The first whole-library `--all` dry run (the 2026-11-03 observe lane)
84
+ crashed with exit 1 forty minutes in: `_decode_numeric_refs` raised
85
+ `ValueError: invalid literal for int() with base 16: 'x2013'` inside the
86
+ prune's content-doc pass, and the exception escaped the sweep's repair
87
+ loop, killing the run and its report.
88
+
89
+ Two fixes:
90
+
91
+ - **The decoder** (epub.py): `_NUMERIC_REF_RE` captured the hex ref's `x`
92
+ into the digits group (`&#x2013;` -> `'x2013'`) and the repl fed the
93
+ whole capture to `int(_, 16)`. XML spells hex character references with
94
+ a lowercase x only, so the regex was right and the int call ate the x;
95
+ the fix strips the prefix before the int. The bug sat dormant since
96
+ v0.58.0 shipped the decode because the resolver runs only on the opt-in
97
+ paths (prune, anchor strip), so the default pass never met it. Library
98
+ census: 36 hex-ref hrefs across 5 books, every one an external URL
99
+ (en-dashes and ampersands in macmillan/tor/techcrunch query strings)
100
+ that the decode reaches before the scheme check discards it. Five new
101
+ tests pin the decode, the internal-href contract extended to hex, and
102
+ the crash shape end-to-end through `strip_missing_file_hrefs`.
103
+ - **The sweep crash guard** (cli.py): an unexpected per-book exception is
104
+ now that book's `error` verdict (`crash (ValueError): ...; not
105
+ applied`), counted in the existing errors tally and flowing to --json
106
+ like every other record, instead of a run-killing traceback. The
107
+ unified trouble exit contract is unchanged. The single-file repair
108
+ verb keeps its traceback: there an operator is watching one book.
109
+
110
+ Suite: 838 tests.
111
+
3
112
  ## v0.61.0 (2026-11-02)
4
113
 
5
114
  ### Issue #25: fix-empty-body injects `<p>&#160;</p>`, not bare `&nbsp;`
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bindery-cli"
7
- version = "0.61.0"
7
+ version = "0.62.0"
8
8
  description = "Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library."
9
9
  readme = "README.md"
10
10
  classifiers = [
@@ -54,6 +54,8 @@ The plugin vendors the core and never gates (the epubcheck latency ruling).
54
54
  | 0.58 | The structural dry run's four rejects (issues #18-#21), each bisected to the root on its specimens: the private-ZipInfo write contract (issue #18: writestr stamps the info it is handed with the DESTINATION offsets, one shared info repointed zin's own lookups into the output file -- all 57 "unreadable" books, the "possible zip bomb" included, were this one bug; the peek also catches BadZipFile per the issue), bracket-encoded renamed references plus the start-tag/PI anchor on both reference rewriters (issue #19: raw brackets are RSC-020 path-illegal -- IJ 108e -> 22e -- and the unanchored regex corrupted display text that teaches HTML -- Hacking's two RSC-016 fatals), the entity-decoding href resolver and prefix-tolerant OPF matchers (issue #20: `&amp;` hrefs vs raw-`&` entries made prune and declare swap the same items on the D&D four, and `<opf:item>` blindness duplicated whole manifests on the Sony three), and the three #21 mechanisms (guide-fragment strip, the post-anchor playOrder re-run, the comment-blind duplicate-id rename) | v0.58.0 |
55
55
  | 0.59 | The dangling-NCX prune (issue #23): `--prune-dangling-ncx-targets` removes navPoint/pageTarget elements whose `<content src>` names a document the archive never contained (RSC-007 the manifest prune cannot reach: no item exists for a file the OPF never declared), node-exact over a balanced stack scanner (dead subtree drops as one span, dead parent spliced above live children, scheme/bare-fragment/comment-hidden/contentless refused, unbalanced walk aborts), with the contract-gated playOrder pass re-run in the same branch -- the hand-surgery-plus-second-run rescue is one gate (fixture 0f/1e/0w -> 0f/0e/0w: one navPoint pruned, 389 playOrder values re-sequenced) | v0.59.0 |
56
56
  | 0.60 | The oracle budget scales on decimal MB and archive entry count (issue #24): the Summa Theologica (10,440,245 bytes = 9.96 binary MiB, 3,831 entries, 3,808 spine docs, 16,456 playOrder findings) is entry-count-bound, not bytes-bound -- measured 384s source and 445s candidate against the flat 300s its bytes computed (the binary 10 MiB divisor ate the size chunk; the book the docs call 10.4 MB never earned one) -- so every sweep double-timed-out and misfiled it as `(epubcheck timeout)`; the size term counts decimal MB now, the entry term adds +60s per started 500 entries above 1,000 (same 1800s cap), the book computes 720s, and a non-zip path falls back to size-only. epubcheck does police the playOrder contract (2 of the source's 6 RSC-005 error entries): default-pass candidate measures 0f/6e -> 0f/4e (accept), scoped `--all` candidate 0f/0e/0w | v0.60.0 |
57
+ | 0.61.1 | The hex-ref href crash and the sweep that survives it: `_NUMERIC_REF_RE` captured the hex ref's `x` into the digits group and `int('x2013', 16)` killed the first whole-library `--all` dry run (2026-11-03 observe lane; 36 hex-ref hrefs across 5 books, every one an external URL the decode reaches before the scheme check discards it; dormant since v0.58.0 because the resolver is opt-in-path-only); the fix strips the prefix before the int, and the sweep's repair loop gains the crash guard -- an unexpected per-book exception is that book's `error` verdict (`crash (Type): ...; not applied`), counted in the existing errors tally, instead of a run-killing traceback (the single-file verb keeps its traceback) | v0.61.1 |
58
+ | 0.62 | The observatory batch (the 2026-11-03 lane's answers): three predicate repairs -- the playOrder contract goes base-free (epubcheck polices sharing/distinctness/gaps, never the base; 107 no-op renumberings silenced), `fix_pagelist_class` inserts the collision-checked id beside the class (class-only made epubcheck demand the id it enabled; the 215-rejection poison), `fix_missing_title` fills the self-closed `<title/>` (the paired-fill branch was dead code; the 70-rejection poison) -- and four new flags for the never-triaged census codes: `--fix-package-version` (OPF-001; literal 1.0 only), `--fix-doctype` (HTM-004; present-but-forbidden declarations only, after the firing census killed insertion), `--prune-invalid-guide-refs` (OPF-032; declared-but-not-a-content-doc targets), `--fix-item-properties` (OPF-014; EPUB3-only, scripted/svg/remote-resources from a whole-book census) | v0.62.0 |
57
59
 
58
60
  ## Open work
59
61
 
@@ -11,7 +11,7 @@ Calibre plugin built from this core.
11
11
  Single source of truth for the version. pyproject.toml must match VERSION below.
12
12
  """
13
13
 
14
- VERSION = "0.61.0"
14
+ VERSION = "0.62.0"
15
15
  __version__ = VERSION
16
16
 
17
17
  from .epub import RepairReport, repair_epub # noqa: E402
@@ -109,6 +109,10 @@ def _flags_from_args(args: argparse.Namespace) -> RepairFlags:
109
109
  unterminated_attr=args.fix_unterminated_attr or all_,
110
110
  unbound_prefix=args.fix_unbound_prefix or all_,
111
111
  unique_identifier=args.fix_unique_identifier or all_,
112
+ package_version=args.fix_package_version or all_,
113
+ doctype=args.fix_doctype or all_,
114
+ prune_guide_refs=args.prune_invalid_guide_refs or all_,
115
+ item_properties=args.fix_item_properties or all_,
112
116
  )
113
117
 
114
118
 
@@ -843,6 +847,26 @@ def run_library(args) -> int:
843
847
  )
844
848
  tqdm.write(f" ERROR {rel}\n unreadable ({reason}): {e}")
845
849
  continue
850
+ except Exception as e:
851
+ # The crash guard (v0.61.1): an unexpected per-book exception (a
852
+ # transform meeting an input shape no test imagined) used to
853
+ # escape as a run-killing traceback that cost a multi-hour sweep
854
+ # its whole report (the 2026-11-03 hex-ref href crash). One
855
+ # book's bug is that book's error verdict, not the run's.
856
+ errors += 1
857
+ records.append(
858
+ Outcome(
859
+ epub,
860
+ "error",
861
+ None,
862
+ None,
863
+ f"crash ({type(e).__name__}): {e}; not applied",
864
+ )
865
+ )
866
+ tqdm.write(
867
+ f" ERROR {rel}\n crash ({type(e).__name__}): {e}; not applied"
868
+ )
869
+ continue
846
870
  records.append(o)
847
871
  if o.status == "nochange":
848
872
  nochange += 1
@@ -1957,6 +1981,59 @@ _REPAIR_FLAG_TABLE: dict[str, list[tuple[str, str, str]]] = {
1957
1981
  "document untouched. Content documents are not touched (their "
1958
1982
  "unbound prefixes have the --strip-bad-attrs drop).",
1959
1983
  ),
1984
+ (
1985
+ "fix_package_version",
1986
+ 'rewrite package version="1.0" to "2.0" (OPF-001)',
1987
+ "rewrite a <package> element whose version attribute is the "
1988
+ "literal 1.0 -- an EPUB version epubcheck cannot parse (OPF-001 "
1989
+ "'error when parsing the EPUB version') -- to 2.0, the conformance "
1990
+ "the 2026-11-03 census's 25 carriers were all written to. Refuses "
1991
+ "everything else: a missing attribute (an OEB-1.0-namespace "
1992
+ "package needs a migration, not an attribute bump) or any other "
1993
+ "spelling. The gate decides whether the profile revalidation is "
1994
+ "a real decrease.",
1995
+ ),
1996
+ (
1997
+ "fix_doctype",
1998
+ "replace a forbidden DOCTYPE with the profile's expected form (HTM-004)",
1999
+ "replace each content document's DOCTYPE when it carries a public "
2000
+ "identifier its package profile forbids: EPUB 3 requires any "
2001
+ "DOCTYPE to be <!DOCTYPE html> (an XHTML 1.x public doctype is a "
2002
+ "spec violation), and EPUB 2's OPS content docs are XHTML 1.1 (an "
2003
+ "XHTML 1.0 public doctype is the census's second flagged shape). "
2004
+ "A semantically identical declaration with different spacing is "
2005
+ "untouched, an ABSENT DOCTYPE is legal in both profiles and left "
2006
+ "alone (the first whole-library firing census measured insertion "
2007
+ "flat on ~2,400 of 2,545 firing books -- it never converges, "
2008
+ "since an equal book never applies), and a DOCTYPE carrying an "
2009
+ "internal subset is never touched (the subset declares entities; "
2010
+ "swapping it would change what the parser resolves).",
2011
+ ),
2012
+ (
2013
+ "prune_invalid_guide_refs",
2014
+ "remove guide references whose target is not a content doc (OPF-032)",
2015
+ "remove guide <reference> elements whose href resolves to a "
2016
+ "manifest item that exists but is not an OPS content document "
2017
+ "(the 2026-11-03 census's 125-book lane: the Random House msr "
2018
+ "guide block pointing cover/thumbimage references at JPEGs). The "
2019
+ "guide is furniture, so removal is content-neutral. A reference "
2020
+ "to an UNDECLARED file is OPF-031 (--declare-missing-items' "
2021
+ "lane) and is left alone, as are external schemes and paired "
2022
+ "elements.",
2023
+ ),
2024
+ (
2025
+ "fix_item_properties",
2026
+ "declare scripted/remote-resources on EPUB3 manifest items (OPF-014)",
2027
+ "scan every content document for what epubcheck wants declared "
2028
+ "(OPF-014 'The property X should be declared in the OPF'): a "
2029
+ "<script> element earns `scripted`, an absolute-scheme src, "
2030
+ "remote <link href>, or remote CSS url() earns "
2031
+ "`remote-resources` -- and merge the tokens into the owning "
2032
+ "manifest item's properties attribute, sorted and deduplicated. "
2033
+ "EPUB 3 packages only (properties is EPUB3 vocabulary; below 3 "
2034
+ "the attribute is itself a finding). Declares reality; changes "
2035
+ "no content.",
2036
+ ),
1960
2037
  ],
1961
2038
  "lossy strips (these delete converter-injected content; accepted on a no-worse bar)": [
1962
2039
  (