|
| 1 | +# Next Task — Prototype Experimental Macro for Conditional Specification Composition |
| 2 | + |
| 3 | +## Selection Metadata |
| 4 | +- **Selection Date:** 2025-11-17 |
| 5 | +- **Chosen Task:** Prototype one experimental macro from the P2 enhancement set, evaluating `@specsIf(condition:)`, `#composed(...)`, or `@deriveSpec(from:)` syntax options and providing usage examples |
| 6 | +- **Source Backlog Entries:** |
| 7 | + - `AGENTS_DOCS/markdown/3.0.0/00_3.0.0_TODO_SpecificationKit.md` lines 25–27 (Experimental Features, P2) |
| 8 | +- **Status:** Selected / Ready to plan implementation |
| 9 | +- **Blocking Issues:** None |
| 10 | + |
| 11 | +## Candidate Review |
| 12 | + |
| 13 | +### Evaluated Options |
| 14 | +1. **Benchmark Baseline Capture** (P2.2 Performance Optimization) |
| 15 | + - Referenced: `AGENTS_DOCS/markdown/00_SpecificationKit_TODO.md` line 110 |
| 16 | + - Status: **Blocked** — requires macOS hardware for CoreData-dependent tests |
| 17 | + - Mitigation: Can be triggered via GitHub Actions when hardware access is scheduled |
| 18 | + - Decision: Defer until macOS CI access available |
| 19 | + |
| 20 | +2. **Prototype Experimental Macro** (P2 Experimental Features) |
| 21 | + - Referenced: `AGENTS_DOCS/markdown/3.0.0/00_3.0.0_TODO_SpecificationKit.md` lines 25–27 |
| 22 | + - Status: **Unblocked** — self-contained, requires no external resources |
| 23 | + - Scope: Three concrete macro options to evaluate |
| 24 | + - Decision: **SELECTED** for implementation |
| 25 | + |
| 26 | +3. **Performance Optimization Investigation** (P2 Performance Optimization) |
| 27 | + - Referenced: `AGENTS_DOCS/markdown/3.0.0/00_3.0.0_TODO_SpecificationKit.md` lines 29–32 |
| 28 | + - Status: Unblocked but requires baseline metrics first |
| 29 | + - Dependency: Benchmark baseline capture (currently blocked) |
| 30 | + - Decision: Defer until benchmarks are available for comparison |
| 31 | + |
| 32 | +### Why This Task Now |
| 33 | + |
| 34 | +1. **No external blockers** — Can proceed independently without waiting for macOS hardware or other infrastructure |
| 35 | +2. **Demonstrates macro evolution** — Extends the existing macro system (`@specs`, `@AutoContext`) with a new, more advanced capability |
| 36 | +3. **Clear evaluation criteria** — Three specific macro options with concrete semantics to compare |
| 37 | +4. **High visibility** — Experimental features are often showcased in release notes and documentation |
| 38 | +5. **Unblocks future design** — Results inform future macro system roadmap (v3.1.0+) |
| 39 | +6. **Library maturity indicator** — Shows SpecificationKit is actively evolving with advanced patterns |
| 40 | + |
| 41 | +## Implementation Notes |
| 42 | + |
| 43 | +### Entry Points / Files to Inspect |
| 44 | +- `Sources/SpecificationKitMacros/MacroPlugin.swift` — Macro registration entry point |
| 45 | +- `Sources/SpecificationKitMacros/AutoContextMacro.swift` — Example of advanced macro implementation with diagnostics |
| 46 | +- `Sources/SpecificationKitMacros/SpecsMacro.swift` — Example of composite specification macro |
| 47 | +- `Tests/SpecificationKitMacrosTests/` — Macro test patterns using swift-macro-testing |
| 48 | +- `CONTRIBUTING.md` — Macro development guidelines |
| 49 | +- `CLAUDE.md` — Build and test commands for macro validation |
| 50 | + |
| 51 | +### Macro Options to Evaluate |
| 52 | + |
| 53 | +**Option 1: `@specsIf(condition:)`** |
| 54 | +- Syntax: `@specsIf(condition: { context in context.isSubscribed })` |
| 55 | +- Behavior: Wraps a specification to conditionally enable/disable based on a closure |
| 56 | +- Pros: Simple, closure-based approach |
| 57 | +- Cons: May require runtime evaluation overhead |
| 58 | + |
| 59 | +**Option 2: `#composed(...)`** |
| 60 | +- Syntax: `#composed([spec1, spec2, spec3], operator: .all)` or similar |
| 61 | +- Behavior: Compile-time composition of multiple specs with operator selection |
| 62 | +- Pros: Explicit operator choice, potential for compile-time optimizations |
| 63 | +- Cons: Declarative syntax may feel inconsistent with attribute macros |
| 64 | + |
| 65 | +**Option 3: `@deriveSpec(from:)`** |
| 66 | +- Syntax: `@deriveSpec(from: MyComposableProtocol.self)` |
| 67 | +- Behavior: Generate specification from a protocol conformance |
| 68 | +- Pros: Protocol-driven, extensible pattern |
| 69 | +- Cons: Complex implementation, may require protocol synthesis |
| 70 | + |
| 71 | +### Acceptance Thoughts |
| 72 | +- Fully working prototype of one chosen macro syntax |
| 73 | +- Comprehensive test coverage (at minimum 5 test cases) demonstrating: |
| 74 | + - Basic usage |
| 75 | + - Edge cases (empty specs, nil conditions, etc.) |
| 76 | + - Error handling and diagnostics |
| 77 | + - Integration with existing specs (`@Satisfies`, `@Decides`) |
| 78 | +- Usage example in documentation or README |
| 79 | +- Diagnostic messages that guide users on correct usage |
| 80 | +- No breaking changes to existing macros |
| 81 | +- Builds without warnings on Swift 5.9+ |
| 82 | + |
| 83 | +### Open Questions / Risks |
| 84 | +1. **Macro complexity** — Does the chosen syntax require advanced macro capabilities, or can it be implemented with current Swift 5.9 macro system? |
| 85 | +2. **Performance impact** — Does the generated code add overhead compared to manual composition? |
| 86 | +3. **User ergonomics** — Is the syntax intuitive for the intended use case? |
| 87 | +4. **Maintenance burden** — Can the macro be documented and maintained alongside existing macros? |
| 88 | + |
| 89 | +## Immediate Next Actions |
| 90 | +1. Read macro implementation examples in `Sources/SpecificationKitMacros/` to understand existing patterns |
| 91 | +2. Design the chosen macro's syntax and semantics (evaluation criteria needed before selection) |
| 92 | +3. Implement macro in `MacroPlugin.swift` with diagnostic support |
| 93 | +4. Write 5+ comprehensive test cases in `SpecificationKitMacrosTests/` |
| 94 | +5. Add usage documentation to `CONTRIBUTING.md` or create a new macro guide |
| 95 | +6. Run full test suite and validate build with `swift build -v` |
| 96 | +7. Update CHANGELOG.md with new P2 feature entry |
| 97 | +8. Archive this selection record and document results in a new task archive |
| 98 | + |
| 99 | +## Reference Documents |
| 100 | +- **Base TODO**: `AGENTS_DOCS/markdown/00_SpecificationKit_TODO.md` |
| 101 | +- **v3.0.0 TODO**: `AGENTS_DOCS/markdown/3.0.0/00_3.0.0_TODO_SpecificationKit.md` |
| 102 | +- **Blockers**: `AGENTS_DOCS/INPROGRESS/blocked.md` |
| 103 | +- **Archive Summary**: `AGENTS_DOCS/TASK_ARCHIVE/ARCHIVE_SUMMARY.md` |
| 104 | +- **Macro Examples**: `Sources/SpecificationKitMacros/*.swift` |
0 commit comments