Skip to content

Single-source and justify tunable constants - #21

Merged
Haakam21 merged 1 commit into
mainfrom
spokane-v1
Sep 18, 2026
Merged

Haakam21 merged 1 commit into
mainfrom
spokane-v1

Conversation

@Haakam21

@Haakam21 Haakam21 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Collapses duplicated numeric literals to single definitions and adds the missing rationale to constants whose values were asserted without one. The de-duplication is behavior-preserving: the ZIP readers now use the CENTRAL_HEADER_BYTES/LOCAL_HEADER_BYTES/EOCD_BYTES constants that already existed but were used only by the writer (15 sites), PDF and XLSX share one BLOCK_SEPARATOR so the separator and the width the cap accounting charges for it cannot disagree, XML_SLICE_CHARS/DOCX_CHUNK_BYTES merge into STREAM_SLICE_UNITS, and GLUED_ATTRIBUTION_RE is assembled from named parts rather than repeating its {0,240} scan budget four times inside one 600-character literal — the generated source is byte-identical to the literal it replaces. The docx maxOutputChars + 2 became CAP_STORAGE_SLACK after probing confirmed it is load-bearing: at +0 the central trim cannot see the overshoot, skips its surrogate check, and emits a lone half as U+FFFD. MAX_SHARED_STRING_INDEX is now derived from MAX_UNCOMPRESSED_BYTES over the 16-byte minimum <si> record, while MAX_PDF_PAGES, TAG_CAPTURE_LIMIT, the sniff/detect constants and body.ts's three lookahead windows (previously one named and two bare, at two different values with no stated reason) gained names and explanations — notably that SNIFF_BYTES is not purely a budget, since isWellFormedUtf16 splits "truncated sample" from "genuinely unpaired" at exactly that boundary. The dataset-tuned body.ts thresholds (the 400-char signature cap, the 0.5 quoted-block ratio, the >=2-line signature body, and the HTML inter-tag windows) are deliberately left undocumented pending the corpus measurements needed to justify them honestly, and are flagged as follow-up; 529 tests, typecheck and build all pass.

🤖 Generated with Claude Code


Open workspace in Conductor

Duplicated literals collapsed to one definition, and the numbers that were
asserted without a reason now carry one.

De-duplication (no behavior change):

- The ZIP readers hardcoded the fixed record sizes 46/30/22 across 15 sites
  while LOCAL_HEADER_BYTES / CENTRAL_HEADER_BYTES / EOCD_BYTES already existed
  and were used only by the writer. Moved the declarations up beside the
  signature constants and substituted them throughout both walks.
- PDF and XLSX both join blocks with '\n\n' and both charged its width as a
  bare 2. Extracted BLOCK_SEPARATOR so the separator and the length the cap
  accounting charges for it cannot disagree.
- XML_SLICE_CHARS and DOCX_CHUNK_BYTES were the same 16 KB serving the same
  purpose under two names; merged into STREAM_SLICE_UNITS.
- GLUED_ATTRIBUTION_RE repeated its {0,240} scan budget four times and its verb
  list twice inside one 600-character literal. Assembled from named parts
  instead; the generated source is byte-identical to the literal it replaces.

Named and justified:

- CAP_STORAGE_SLACK for the docx `maxOutputChars + 2`. Verified load-bearing:
  at +0 the central trim cannot see the overshoot, skips its surrogate check,
  and emits a lone half as U+FFFD (tests/docx-streaming surrogate test fails).
- MAX_SHARED_STRING_INDEX for the bare 10_000_000, now derived from
  MAX_UNCOMPRESSED_BYTES over the 16-byte minimum <si> record.
- TAG_CAPTURE_LIMIT, MAX_PDF_PAGES, SNIFF_BYTES, SNIFF_TEXT_RATIO,
  DETECT_SAMPLE_BYTES and DETECT_MIN_CONFIDENCE gained the missing rationale.
  SNIFF_BYTES in particular is not only a budget: isWellFormedUtf16 splits
  "truncated sample" from "genuinely unpaired" at exactly that boundary.
- body.ts had three lookahead windows, one named and two bare, at two different
  values with no stated reason for the difference. Now ATTRIBUTION_WRAP_LINES,
  DIVIDER_LOOKAHEAD_LINES and HEADER_BLOCK_LINES, each explaining what bounds it.

Still undocumented and flagged for follow-up: the dataset-tuned thresholds in
body.ts (the 400-char signature cap, the 0.5 quoted-block ratio, the >=2-line
signature body, and the HTML inter-tag windows 200/250/80/25/40/60).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Haakam21
Haakam21 merged commit ba7b16e into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants