Skip to content

✨ feat: Add named capture in module patterns for back-referencing in allow/deny#17

Merged
heumsi merged 6 commits intomainfrom
feat/named-capture-pattern
Mar 30, 2026
Merged

✨ feat: Add named capture in module patterns for back-referencing in allow/deny#17
heumsi merged 6 commits intomainfrom
feat/named-capture-pattern

Conversation

@heumsi
Copy link
Copy Markdown
Owner

@heumsi heumsi commented Mar 30, 2026

Summary

  • Add {name} capture syntax in modules patterns that can be back-referenced in allow/deny rules
  • Enables cross-context isolation without duplicating per-context rules (e.g., Hexagonal Architecture with multiple Bounded Contexts)
  • Fully backward compatible — existing configs work without changes

Example

rules:
  - name: domain-layer
    modules: contexts.{context}.domain
    allow:
      local: [contexts.{context}.domain, shared.domain]

When matching contexts.boards.domain, {context} captures "boards", so only contexts.boards.domain is allowed — not contexts.auth.domain.

Changes

  • matcher.py: Add match_pattern_with_captures(), update find_matching_rules() to return captures
  • checker.py: Add resolve_captures(), update check_import() with optional captures parameter
  • cli.py: Thread captures from rule matching to import checking
  • README.md: Add Named Capture documentation section, update Hexagonal Architecture example
  • 22 new tests (75 total, all passing)

Closes #16

Test plan

  • Unit tests for match_pattern_with_captures (single/multiple captures, duplicate name consistency, coexistence with */**, backtracking)
  • Unit tests for resolve_captures (single/multiple/no placeholders, unresolved placeholders)
  • Integration tests for cross-context isolation (allowed and violation cases)
  • Backward compatibility test (existing behavior without captures)
  • All 75 tests pass
  • ruff lint clean

🤖 Generated with Claude Code

heumsi and others added 6 commits March 30, 2026 19:11
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Change return type from list[Rule] to list[tuple[Rule, dict[str, str]]],
and update cli.py and tests to unpack tuples correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…he first

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@heumsi heumsi merged commit 9e56e8e into main Mar 30, 2026
5 checks passed
@heumsi heumsi deleted the feat/named-capture-pattern branch March 30, 2026 14:20
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.

Feature: Named capture in module patterns for back-referencing in allow/deny

1 participant