feat: add measurement-validator module (Phase 1)#2
Draft
Conversation
Agent-Logs-Url: https://github.com/Himaan1998Y/pretext/sessions/64d3a3ab-a278-4221-abf3-57b5769d9c26 Co-authored-by: Himaan1998Y <210527591+Himaan1998Y@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Himaan1998Y/pretext/sessions/64d3a3ab-a278-4221-abf3-57b5769d9c26 Co-authored-by: Himaan1998Y <210527591+Himaan1998Y@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement Measurement Validator module in Pretext codebase
feat: add measurement-validator module (Phase 1)
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new
src/measurement-validator/module that compares Pretext's canvas-based measurements against actual browser DOM rendering (via Range API) to surface per-line divergences and classify root causes.New modules
types.ts— Core types:MeasurementSample,ComparisonResult,DivergenceMetrics,LineComparison,Severity; severity thresholds andclassifySeverity()dom-adapter.ts—measureDOM(): hidden container +document.fonts.ready+ Range API +Intl.Segmentergrapheme walk to extract per-line widths as ground truthcomparator.ts—compare()/compareAll(): runsprepareWithSegments+layoutWithLinesalongsidemeasureDOM, diffs line widths, and applies lightweight root-cause heuristics (bidi/RTL char ranges, emoji, line-count mismatch, Safari kerning)report-generator.ts—buildReport(),toJSON(),toConsoleText(),printReport()index.ts— Public re-exportsTests & fixtures
test/measurement-validator.test.ts— severity classification, report aggregation, Pretext layout integration, comparator arithmetic; uses the same fake canvas backend aslayout.test.tstest/fixtures/english-samples.json— 10 English samples (varied widths, font sizes,pre-wrap, forced grapheme breaks)Docs
docs/measurement-validator.md— API reference, severity table, Phase 1 limitationsUsage
Severity thresholds
exactminormajorcriticalDOM-dependent paths (
measureDOM,compare,compareAll) require a real browser environment — JSDOM has no layout engine and will return zero-width lines.Original prompt
Phase 1: Measurement Validator Implementation - BUILD STEP
OBJECTIVE
Implement the Measurement Validator module from scratch in the Pretext codebase. This is the FULL Phase 1 build, not a PR yet - we'll test locally first, then create PR.
WHAT WE'RE BUILDING
Core Components
Directory Structure
FILES TO CREATE
1. src/measurement-validator/types.ts
Complete type definitions for the validator module.
2. src/measurement-validator/dom-adapter.ts
Measures text using actual browser DOM rendering (ground truth).
3. src/measurement-validator/comparator.ts
Core comparison engine - compares Pretext measurements against DOM.
4. src/measurement-validator/report-generator.ts
Formats results into JSON, console summaries, and detailed reports.
5. src/measurement-validator/index.ts
Public API exports.
6. test/measurement-validator.test.ts
Integration tests covering all major flows.
7. test/fixtures/english-samples.json
10 English test cases with varying widths and fonts.
8. docs/measurement-validator.md
Getting started guide with examples and API reference.
IMPLEMENTATION NOTES
Design Decisions
Performance Target
Testing Strategy
SUCCESS CRITERIA
✅ All files created and compile without errors
✅ Tests pass locally
✅ Can measure and compare Pretext vs DOM
✅ All 10 fixtures pass (>99% accuracy within 0.5px)
✅ No TypeScript errors
✅ Ready for code review and PR creation
The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: JACKPOT. Let me map this ecosystem map more carefully:
PRETEXT ECOSYSTEM: ACTUAL SHIPPING PRODUCTS
Looking at the
@chenglou/pretextusage across GitHub (10+ results shown, likely 50+):Production Apps Already Using Pretext:
1. fastrepl/char — Code collaboration platform (HYPR web)
@chenglou/pretext: ^0.0.42. vectorize-io/hindsight — Semantic memory/AI system (Control plane)
@chenglou/pretext: ^0.0.33. mayneyao/eidos — Database/spreadsheet app
@chenglou/pretext: ^0.0.34. liyown/marknative — Markdown → PNG/SVG rendering
@chenglou/pretext: ^0.0.3skia-canvasfor drawing5. Simon-He95/markstream-vue — Rich markdown editor
@chenglou/pretext: ^0.0.36. xiaoiver/infinite-canvas-tutorial — Infinite whiteboard/canvas
@chenglou/pretext: ^0.0.37. guangzan/tona — Blog engine/CMS
@chenglou/pretext: catalog:8. KashyapTan/Xpdite — AI/ML desktop application
@chenglou/pretext: ^0.0.49. zuoban/zb-reader — EPUB reader
@chenglou/pretext: ^0.0.3CRITICAL INSIGHT: The Real Problem
These apps all have the same issue:
What They ACTUALLY Need
Based on real shipped products:
TIER 0: BLOCKING EVERYONE (Months of wasted dev time)
**GEM #...
This pull request was created from Copilot chat.