-
Notifications
You must be signed in to change notification settings - Fork 151
Apply PR #1020 review nits: type precision, reason constant, frozenset family validation #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d142a9a
a6d6673
292bda1
fb314d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,31 +164,42 @@ def _get_validation_suggestion(error_msg): | |
|
|
||
|
|
||
| def _resolve_compile_target(target): | ||
| """Map CLI target input to compiler-understood target string. | ||
| """Map CLI target input to a compiler-understood target. | ||
|
|
||
| The compiler understands ``"vscode"``, ``"claude"``, ``"gemini"``, | ||
| and ``"all"``. Multi-target lists are mapped to the narrowest | ||
| equivalent; any combination of two or more distinct compiler | ||
| families collapses to ``"all"``. | ||
| The compiler understands single-string targets (``"vscode"``, | ||
| ``"claude"``, ``"gemini"``, ``"all"``) and ``frozenset`` targets | ||
| containing compiler-family names (``"agents"``, ``"claude"``, | ||
| ``"gemini"``). | ||
|
|
||
| Multi-target lists are mapped to the narrowest representation: | ||
| a single string when only one compiler family is needed, or a | ||
| ``frozenset`` of families when multiple are needed. This avoids | ||
| collapsing to ``"all"`` (which would incorrectly generate files | ||
| for every family). | ||
|
|
||
| Args: | ||
| target: A single target string, a list of target strings, or ``None``. | ||
|
|
||
| Returns: | ||
| A single string (or ``None``) suitable for :func:`detect_target`. | ||
| A single string, a ``frozenset`` of compiler families, or ``None``. | ||
| """ | ||
| if target is None: | ||
| return None # will trigger detect_target() auto-detection | ||
| if isinstance(target, list): | ||
| target_set = set(target) | ||
| has_agents_family = bool( | ||
| target_set & {"copilot", "vscode", "agents", "cursor", "opencode", "codex"} | ||
| ) | ||
| agents_family = {"copilot", "vscode", "agents", "cursor", "opencode", "codex"} | ||
| has_agents_family = bool(target_set & agents_family) | ||
| has_claude = "claude" in target_set | ||
| has_gemini = "gemini" in target_set | ||
| distinct = sum([has_agents_family, has_claude, has_gemini]) | ||
| if distinct >= 2: | ||
| return "all" | ||
| families = set() | ||
| if has_agents_family: | ||
| families.add("agents") | ||
| if has_claude: | ||
| families.add("claude") | ||
| if has_gemini: | ||
| families.add("gemini") | ||
| if len(families) >= 2: | ||
| return frozenset(families) | ||
| elif has_claude: | ||
| return "claude" | ||
| elif has_gemini: | ||
|
|
@@ -377,7 +388,11 @@ def compile( | |
| logger.start("Starting context compilation...", symbol="cogs") | ||
|
|
||
| # Auto-detect target if not explicitly provided | ||
| from ...core.target_detection import detect_target, get_target_description | ||
| from ...core.target_detection import ( | ||
| REASON_NO_TARGET_FOLDER, | ||
| detect_target, | ||
| get_target_description, | ||
| ) | ||
|
|
||
| # Get config target from apm.yml if available | ||
| config_target = None | ||
|
|
@@ -390,18 +405,27 @@ def compile( | |
| # No apm.yml or parsing error - proceed with auto-detection | ||
| pass | ||
|
|
||
| # Resolve list targets to compiler-understood string | ||
| # Resolve list targets to compiler-understood value | ||
| compile_target = _resolve_compile_target(target) | ||
| # Also handle config_target being a list (from apm.yml target: [claude, copilot]) | ||
| compile_config_target = _resolve_compile_target(config_target) | ||
| detected_target, detection_reason = detect_target( | ||
| project_root=Path("."), | ||
| explicit_target=compile_target, | ||
| config_target=compile_config_target, | ||
| ) | ||
|
|
||
| # Map 'minimal' to 'vscode' for the compiler (AGENTS.md only, no folder integration) | ||
| effective_target = detected_target if detected_target != "minimal" else "vscode" | ||
| # A frozenset means multiple compiler families were explicitly | ||
| # requested -- bypass detect_target() since it only handles strings. | ||
| if isinstance(compile_target, frozenset): | ||
| effective_target = compile_target | ||
| detection_reason = "explicit --target flag" | ||
| elif isinstance(compile_config_target, frozenset) and compile_target is None: | ||
| effective_target = compile_config_target | ||
| detection_reason = "apm.yml target" | ||
| else: | ||
| detected_target, detection_reason = detect_target( | ||
| project_root=Path("."), | ||
| explicit_target=compile_target, | ||
| config_target=compile_config_target, | ||
| ) | ||
| # Map 'minimal' to 'vscode' for the compiler (AGENTS.md only, no folder integration) | ||
| effective_target = detected_target if detected_target != "minimal" else "vscode" | ||
|
|
||
| # Build config with distributed compilation flags (Task 7) | ||
| config = CompilationConfig.from_apm_yml( | ||
|
|
@@ -426,26 +450,33 @@ def compile( | |
| if isinstance(target, list): | ||
| # Multi-target list: show what the compiler will produce | ||
| _target_label = ",".join(target) | ||
| if effective_target == "all": | ||
| logger.progress( | ||
| f"Compiling for AGENTS.md + CLAUDE.md (--target {_target_label})" | ||
| ) | ||
| elif effective_target == "claude": | ||
| logger.progress( | ||
| f"Compiling for CLAUDE.md (--target {_target_label})" | ||
| ) | ||
| else: | ||
| logger.progress( | ||
| f"Compiling for AGENTS.md (--target {_target_label})" | ||
| ) | ||
| elif detected_target == "minimal": | ||
| from ...core.target_detection import ( | ||
| should_compile_agents_md, | ||
| should_compile_claude_md, | ||
| should_compile_gemini_md, | ||
| ) | ||
| _parts = [] | ||
| if should_compile_agents_md(effective_target): | ||
| _parts.append("AGENTS.md") | ||
| if should_compile_claude_md(effective_target): | ||
| _parts.append("CLAUDE.md") | ||
| if should_compile_gemini_md(effective_target): | ||
| _parts.append("GEMINI.md") | ||
| logger.progress( | ||
| f"Compiling for {' + '.join(_parts)} (--target {_target_label})" | ||
| ) | ||
| elif ( | ||
| isinstance(effective_target, str) | ||
| and effective_target == "vscode" | ||
| and detection_reason == REASON_NO_TARGET_FOLDER | ||
| ): | ||
| logger.progress(f"Compiling for AGENTS.md only ({detection_reason})") | ||
| logger.progress( | ||
| " Create .github/, .claude/, .codex/, .opencode/ or .cursor/ folder for full integration", | ||
| symbol="light_bulb", | ||
| ) | ||
| else: | ||
| description = get_target_description(detected_target) | ||
| description = get_target_description(effective_target) | ||
| logger.progress( | ||
| f"Compiling for {description} - {detection_reason}" | ||
|
Comment on lines
450
to
481
|
||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changelog entry appears to reference the issue number (#1019) rather than the PR that delivered the fix, and it doesn't end with a PR number as required by the project's Keep a Changelog convention. Update the line to end with the actual PR number (likely #1020 and/or this follow-up PR), and consider wrapping
GEMINI.mdin backticks for consistency with nearby entries.