fix(cache): extract shared date patterns to internal/dates and drop false positives
Merged
MO
15d ago+39+39+01234567890123456789-13-13-01234567890123456789
What and why
Follow-up to #1496 and #1498 addressing maintainer review feedback:
- Extracted shared date and time regex patterns (
ISO_DATE,CLOCK_TIME,MONTH_DAY_DATE,DAY_MONTH_DATE) into neutralsrc/internal/dates.ts, shared by bothagent/derived.tsandcache/anchors.ts. KeptMONTHandDAYunexported to avoid unused exports. - Rebased on
main(now containing #1498) and dropped duplicateddeltaMismatchtests. - Reverted unrelated import churn in
anchors.tsand collapsed blank lines inderived.ts. - Eliminated false-positive volatile anchor matches on non-date terms (e.g.
Marketing 12,Mayor 3,Augusta 3,12 Marketing) which previously matched due to loose[a-z]*month prefixes. - Updated unit test in
packages/e2e/tests/unit/trace-anchors.test.tswith inputs that main actually matched to prove the fix. - User-facing changeset in
.changeset/unify-date-anchor-patterns.md. - Note on non-English months: Main's
[a-z]*pattern previously matched some non-English month words by accident (e.g.3 septembre,Octobre 3,Juni 3,Marzo 3). With this change they are no longer treated as volatile text anchors (leading safely to a cache handoff rather than a false pass). - Note on
derived.tsspacing: The shared pattern uses\s+instead of the previous single space between month, day, and year, so inputs with multiple spaces or whitespace tabs (e.g.Oct 26,Oct\t26,26\nOct) now also count as dates inderivedReason.
Issue
Follow-up refactor to #1496 / #1498
Verified
Ran regression checks covering:
- Dates with ordinal suffixes in both month-first and day-first formats.
- False positive checks against
Marketing 12,Mayor 3,Augusta 3, and12 Marketing. - Unit tests in
packages/e2e/tests/unit/trace-anchors.test.tsandagent/derived.tsintegration.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package - Breaking change: not applicable
- Docs updated in the same PR: not applicable
- Contract change: not applicable
- Engine contract change: not applicable