Skip to content

feat: optional active_grammars with shipped-grammar fallback - #20

Merged
azaharizaman merged 8 commits into
mainfrom
feature/optional-active-grammars
Aug 11, 2026
Merged

azaharizaman merged 8 commits into
mainfrom
feature/optional-active-grammars

Conversation

@azaharizaman

@azaharizaman azaharizaman commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Makes active_grammars optional so every capability accepts new shipped grammars with a single-line change to get_grammars().

Change

  • CapabilityContract.active_grammars returns None by default (was abstract) — the engine falls back to the capability's shipped get_grammars() names, in order.
  • Deleted the static all-active overrides from Country, Currency, Date, Money, Phone, URL — no contract edit needed to add a grammar there anymore.
  • Email, IP, ISBN keep their feature-flag-gated active_grammars overrides.
  • Community grammars stay opt-in via extra_grammars; the fallback never activates them.
  • Behavior is byte-identical: for every all-active capability, the fallback order equals the old declared list order (same-span tiebreak preserved).

Also included: the slash-ISO date grammar (YYYY/MM/DD) with its new contributor guide HOW_TO_ADD_NEW_GRAMMAR.md, which uses that grammar as its worked example.

Verification

  • ruff check paxman/ tests/ + ruff format --check paxman/ tests/ — clean
  • pyright — 0 errors
  • import-linter lint — contracts kept
  • pytest — 2082 passed
  • Per-package coverage ≥ 95% (core 95.77%)

Commits (8)

  1. feat(date): slash-ISO grammar + tests
  2. docs(date): README + new-grammar guide
  3. refactor(core): optional active_grammars + engine fallback + tests
    4–6. refactor(capabilities): drop static overrides (by capability pair, with paired test rewrites)
    7–8. docs: guides, architecture, audit (F5 marked resolved), AGENTS.md

Summary by CodeRabbit

  • New Features

    • Added recognition for slash-delimited ISO dates such as 2024/3/7, with canonical ISO formatting and support for single-digit components.
    • Existing date formats and ambiguity handling remain supported.
  • Improvements

    • Capabilities now use all shipped recognition formats by default when no specific selection is provided.
    • Optional selections continue to support feature-gated recognition and explicitly added extensions.
  • Documentation

    • Expanded guides and architecture documentation for grammar selection, date formats, and adding new capabilities or grammars.

Slash-delimited ISO dates share ISO 8601's calendar-date position mapping
and canonical form, so the new grammar wires into the existing
Section 4.3.1 rule via target_grammars. Recognizes 4-digit-year-first
slash dates that previously resolved MISSING.
README gains the slash-ISO format in the Date table, capability blurb,
and a worked example. HOW_TO_ADD_NEW_GRAMMAR.md is a new contributor
guide for teaching an existing capability a new representation, using
the slash-ISO grammar as its validated worked example.
CapabilityContract.active_grammars returns None instead of being abstract;
the engine falls back to the capability's shipped get_grammars() names,
in order. Adding a grammar to get_grammars() now activates it with no
contract edit. Community grammars stay opt-in via extra_grammars — the
fallback never activates them. Gated capabilities (Email, IP, ISBN) keep
their feature-flag overrides; all-active capabilities drop them next.
Both contracts return None now; the engine runs every shipped grammar.
HOW_TO_ADD_NEW_CAPABILITY.md: active_grammars is optional — implement
only for feature-gated recognition; static always-all overrides are now
an anti-pattern. ARCHITECTURE.md and CONTEXT.md describe the engine's
fallback to every shipped get_grammars() entry. The homogeneity audit
marks F5 (static vs toggleable active_grammars) resolved 2026-08-11.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR makes active_grammars optional, runs all shipped grammars when it is None, preserves explicit extra-grammar opt-in, removes static all-active overrides, and adds Slash-ISO date recognition with documentation and tests.

Changes

Grammar activation defaults

Layer / File(s) Summary
Optional contract activation
paxman/core/*, CONTEXT.md, HOW_TO_ADD_NEW_CAPABILITY.md, paxman/capabilities/*/AGENTS.md
The base contract returns None. The protocol and contributor guidance describe all-shipped-grammar fallback.
Engine grammar selection
paxman/engine/orchestrator.py, tests/integration/test_recognition_seam.py, ARCHITECTURE.md
The orchestrator activates shipped grammars by default and keeps community grammars opt-in through extra_grammars.
Capability contract migration
paxman/capabilities/{Country,Currency,Money,Phone,URL}/contract.py, tests/capabilities/{country,currency,money,phone,url}/*
Static all-active overrides were removed. Tests verify None defaults and shipped grammar lists.
Audit updates
capability_homogeneity_audit.md
The F5 finding is marked resolved.

Slash-ISO date recognition

Layer / File(s) Summary
Grammar and rule wiring
paxman/capabilities/Date/grammar/slash_iso_recognition.py, paxman/capabilities/Date/capability.py, paxman/capabilities/Date/rules/iso_8601_ed2019.py
Date recognition now accepts YYYY/MM/DD, and the ISO rule validates and normalizes both slash- and dash-delimited forms.
Validation and documentation
tests/capabilities/date/*, tests/integration/test_date_capability.py, README.md, CONTEXT.md, HOW_TO_ADD_NEW_GRAMMAR.md
Tests cover matching, spans, ambiguity, invalid dates, canonicalization, and zero-padding. Documentation describes the fourth grammar and extension process.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making active_grammars optional and adding a shipped-grammar fallback.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
HOW_TO_ADD_NEW_GRAMMAR.md (1)

15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the root specification a required first step.

Line 15 only references HOW_TO_ADD_NEW_CAPABILITY.md. Require contributors to read it before modifying a capability directory. State that the root specification prevails if this guide conflicts with it.

Based on learnings: “Before modifying a capability directory, read the root HOW_TO_ADD_NEW_CAPABILITY.md; where it conflicts with this compact guide, the root specification prevails.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@HOW_TO_ADD_NEW_GRAMMAR.md` at line 15, Update the introductory guidance in
HOW_TO_ADD_NEW_GRAMMAR.md to require contributors to read
HOW_TO_ADD_NEW_CAPABILITY.md before modifying any capability directory, and
explicitly state that the root specification takes precedence whenever the two
guides conflict.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@HOW_TO_ADD_NEW_GRAMMAR.md`:
- Line 15: Update the introductory guidance in HOW_TO_ADD_NEW_GRAMMAR.md to
require contributors to read HOW_TO_ADD_NEW_CAPABILITY.md before modifying any
capability directory, and explicitly state that the root specification takes
precedence whenever the two guides conflict.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 77a1abf4-44c1-4506-b354-0aa08e50586d

📥 Commits

Reviewing files that changed from the base of the PR and between 7e51493 and c3c667e.

📒 Files selected for processing (31)
  • ARCHITECTURE.md
  • CONTEXT.md
  • HOW_TO_ADD_NEW_CAPABILITY.md
  • HOW_TO_ADD_NEW_GRAMMAR.md
  • README.md
  • capability_homogeneity_audit.md
  • paxman/capabilities/AGENTS.md
  • paxman/capabilities/Country/contract.py
  • paxman/capabilities/Currency/contract.py
  • paxman/capabilities/Date/capability.py
  • paxman/capabilities/Date/contract.py
  • paxman/capabilities/Date/grammar/slash_iso_recognition.py
  • paxman/capabilities/Date/rules/iso_8601_ed2019.py
  • paxman/capabilities/Money/contract.py
  • paxman/capabilities/Phone/contract.py
  • paxman/capabilities/URL/contract.py
  • paxman/core/AGENTS.md
  • paxman/core/capability_contract.py
  • paxman/core/contract.py
  • paxman/engine/orchestrator.py
  • tests/capabilities/country/test_capability.py
  • tests/capabilities/currency/test_contract.py
  • tests/capabilities/date/test_capability.py
  • tests/capabilities/date/test_grammar.py
  • tests/capabilities/money/test_contract.py
  • tests/capabilities/phone/test_capability.py
  • tests/capabilities/url/test_capability.py
  • tests/capabilities/url/test_contract.py
  • tests/integration/test_date_capability.py
  • tests/integration/test_recognition_seam.py
  • tests/unit/test_capability_contract.py
💤 Files with no reviewable changes (6)
  • paxman/capabilities/Phone/contract.py
  • paxman/capabilities/Money/contract.py
  • paxman/capabilities/Country/contract.py
  • paxman/capabilities/Currency/contract.py
  • paxman/capabilities/URL/contract.py
  • paxman/capabilities/Date/contract.py

@azaharizaman
azaharizaman merged commit 6987586 into main Aug 11, 2026
1 of 5 checks passed
@azaharizaman
azaharizaman deleted the feature/optional-active-grammars branch August 11, 2026 15:27
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