|
20 | 20 | ) |
21 | 21 | from .link_resolver import resolve_markdown_links, validate_link_targets |
22 | 22 | from ..utils.paths import portable_relpath |
| 23 | +from ..core.target_detection import should_compile_agents_md, should_compile_claude_md |
| 24 | + |
| 25 | + |
| 26 | +# User-facing target aliases that map to the canonical "vscode" target. |
| 27 | +# Kept in sync with target_detection.detect_target(). |
| 28 | +_VSCODE_TARGET_ALIASES = ("copilot", "agents") |
| 29 | +_KNOWN_TARGETS = ( |
| 30 | + "vscode", "claude", "cursor", "opencode", "codex", "all", "minimal", |
| 31 | +) + _VSCODE_TARGET_ALIASES |
23 | 32 |
|
24 | 33 |
|
25 | 34 | @dataclass |
@@ -199,17 +208,52 @@ def compile(self, config: CompilationConfig, primitives: Optional[PrimitiveColle |
199 | 208 | exclude_patterns=config.exclude, |
200 | 209 | ) |
201 | 210 |
|
202 | | - # Route to targets based on config.target |
| 211 | + # Route to targets based on config.target. |
| 212 | + # Use target_detection helpers as the single source of truth so |
| 213 | + # new targets (codex, opencode, cursor, minimal, ...) route |
| 214 | + # correctly without touching this method again. |
| 215 | + routing_target = ( |
| 216 | + "vscode" if config.target in _VSCODE_TARGET_ALIASES else config.target |
| 217 | + ) |
| 218 | + |
| 219 | + if routing_target not in _KNOWN_TARGETS and config.target not in _KNOWN_TARGETS: |
| 220 | + self.errors.append( |
| 221 | + f"Unknown compilation target: {config.target!r}. " |
| 222 | + f"Expected one of: {', '.join(sorted(set(_KNOWN_TARGETS)))}" |
| 223 | + ) |
| 224 | + return CompilationResult( |
| 225 | + success=False, |
| 226 | + output_path="", |
| 227 | + content="", |
| 228 | + warnings=self.warnings.copy(), |
| 229 | + errors=self.errors.copy(), |
| 230 | + stats={}, |
| 231 | + ) |
| 232 | + |
203 | 233 | results: List[CompilationResult] = [] |
204 | | - |
205 | | - # AGENTS.md target (vscode/agents) |
206 | | - if config.target in ("vscode", "agents", "all"): |
| 234 | + |
| 235 | + if should_compile_agents_md(routing_target): |
207 | 236 | results.append(self._compile_agents_md(config, primitives)) |
208 | | - |
209 | | - # CLAUDE.md target |
210 | | - if config.target in ("claude", "all"): |
| 237 | + |
| 238 | + if should_compile_claude_md(routing_target): |
211 | 239 | results.append(self._compile_claude_md(config, primitives)) |
212 | | - |
| 240 | + |
| 241 | + # Defensive: should never happen for a known target, but guards |
| 242 | + # against future target_detection drift silently producing no-ops. |
| 243 | + if not results: |
| 244 | + self.errors.append( |
| 245 | + f"Target {config.target!r} did not route to any compiler. " |
| 246 | + "This is an internal bug in target routing." |
| 247 | + ) |
| 248 | + return CompilationResult( |
| 249 | + success=False, |
| 250 | + output_path="", |
| 251 | + content="", |
| 252 | + warnings=self.warnings.copy(), |
| 253 | + errors=self.errors.copy(), |
| 254 | + stats={}, |
| 255 | + ) |
| 256 | + |
213 | 257 | # Merge results from all targets |
214 | 258 | return self._merge_results(results) |
215 | 259 |
|
|
0 commit comments