fix(cache): extract shared date patterns to internal/dates and drop false positives

Merged
MO
15d ago
+39-13

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 neutral src/internal/dates.ts, shared by both agent/derived.ts and cache/anchors.ts. Kept MONTH and DAY unexported to avoid unused exports.
  • Rebased on main (now containing #1498) and dropped duplicated deltaMismatch tests.
  • Reverted unrelated import churn in anchors.ts and collapsed blank lines in derived.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.ts with 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.ts spacing: 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 in derivedReason.

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, and 12 Marketing.
  • Unit tests in packages/e2e/tests/unit/trace-anchors.test.ts and agent/derived.ts integration.

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