Skip to content

feat: add preservePatterns for domain-specific preservation#13

Merged
SimplyLiz merged 1 commit intodevelopfrom
feature/preserve-patterns
Mar 10, 2026
Merged

feat: add preservePatterns for domain-specific preservation#13
SimplyLiz merged 1 commit intodevelopfrom
feature/preserve-patterns

Conversation

@SimplyLiz
Copy link
Owner

Summary

  • Adds preservePatterns option to CompressOptions — users supply regex patterns that force hard T0 preservation, enabling domain-specific content protection (legal, medical, academic) without the heuristic classifier
  • Patterns are checked after built-in classification but before JSON detection, consistent with the existing rule priority chain
  • Tracks messages_pattern_preserved stat in CompressResult.compression

Changes

File Change
src/types.ts New option field + new stat field
src/compress.ts Thread patterns into classifyAll, track stat
tests/compress.test.ts 7 new tests (match, no-match, multi-pattern, empty array, code-split precedence, dedup precedence, tokenBudget integration)
docs/api-reference.md Document option and stat
docs/preservation-rules.md Priority table update, new section with legal/medical/academic examples

Test plan

  • All 343 tests pass (npm test)
  • Lint clean (npm run lint)
  • Format clean (npm run format:check)
  • Benchmarks pass with no regression (npm run bench)

…ation

Users can now supply regex patterns that force hard T0 preservation,
enabling domain-specific content protection (legal citations, medical
dosages, academic references) without relying on the heuristic classifier.

Patterns are checked after built-in classification but before JSON
detection. A new stat messages_pattern_preserved tracks how many
messages were preserved by custom patterns.
@SimplyLiz SimplyLiz merged commit 7ac0429 into develop Mar 10, 2026
8 of 11 checks passed
@SimplyLiz SimplyLiz deleted the feature/preserve-patterns branch March 10, 2026 03:25
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.

1 participant