fix(compile): emit and clean up copilot root instructions#930
fix(compile): emit and clean up copilot root instructions#930WilliamK112 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR extends APM's compilation pipeline to generate GitHub Copilot root instructions (.github/copilot-instructions.md) from global .apm/instructions/*.instructions.md content, while preserving the minimal target's AGENTS.md-only behavior and cleaning up stale generated root instructions when they no longer apply.
Changes:
- Emit
.github/copilot-instructions.mdduringapm compile(for Copilot-capable targets) and remove stale generated copies when switching targets or when only scopedapplyTorules remain. - Preserve
minimalsemantics by no longer remappingminimaltovscodein the compile CLI. - Add target metadata/description updates and comprehensive unit + integration test coverage for the new behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/apm_cli/compilation/agents_compiler.py |
Implements generation + cleanup logic for Copilot root instructions and tracks related stats. |
src/apm_cli/commands/compile/cli.py |
Preserves minimal as a first-class compilation target instead of mapping it to vscode. |
src/apm_cli/core/target_detection.py |
Adds routing helper for Copilot root instructions and updates target descriptions. |
src/apm_cli/integration/targets.py |
Tracks Copilot root generated file in target metadata (generated_files). |
tests/unit/compilation/test_compile_target_flag.py |
Unit tests for emitting/removing/preserving Copilot root instructions across targets and scenarios. |
tests/integration/test_compile_copilot_root_instructions.py |
CLI-level coverage for emission + idempotency + stale cleanup behavior. |
tests/unit/core/test_target_detection.py |
Tests new target-routing helper and updated target descriptions. |
tests/unit/integration/test_targets.py |
Ensures Copilot target profile lists the root generated file. |
| # Keep the detected target intact so the compiler can preserve | ||
| # minimal-mode semantics (AGENTS.md only, no .github side outputs). | ||
| effective_target = detected_target |
There was a problem hiding this comment.
Now that effective_target can remain minimal, make sure every subsequent compile pass in this command uses the same target. In the legacy --single-agents path, an intermediate CompilationConfig(...) is constructed without target=... (so it defaults to all), which can unexpectedly route through CLAUDE compilation and potentially alter what gets injected/written to AGENTS.md. Propagating effective_target (or avoiding the second compile) would keep minimal-mode semantics intact.
| result.stats["copilot_root_instructions_unchanged"] = 1 | ||
| return result | ||
|
|
||
| output_path.write_text(content, encoding="utf-8") | ||
| result.stats["copilot_root_instructions_written"] = 1 |
There was a problem hiding this comment.
The write path for .github/copilot-instructions.md will overwrite an existing manually-authored file whenever global instructions exist (the only preservation logic is in cleanup, not generation). This risks clobbering user content and contradicts the repo/docs expectation that existing config files are not modified. Consider only writing when the file is missing or already marked as APM-generated (marker present); otherwise, warn and skip (or require an explicit force flag).
| def _generate_copilot_root_instructions_content( | ||
| self, | ||
| instructions, | ||
| config: CompilationConfig, | ||
| ) -> str: |
There was a problem hiding this comment.
_generate_copilot_root_instructions_content() adds new public-ish helper logic but leaves the instructions parameter untyped. Please add an explicit type (e.g., a Sequence/List of Instruction primitives) to match the codebase's type-hinting guideline for new/changed code.
| descriptions = { | ||
| "vscode": "AGENTS.md + .github/prompts/ + .github/agents/", | ||
| "vscode": "AGENTS.md + .github/copilot-instructions.md + .github/prompts/ + .github/agents/", | ||
| "claude": "CLAUDE.md + .claude/commands/ + .claude/agents/ + .claude/skills/", |
There was a problem hiding this comment.
get_target_description() is used by apm compile logging, but the vscode/all descriptions currently list .github/prompts/ and .github/agents/ as generated outputs. Those are installed/deployed by apm install integrators, not produced by apm compile (agents_compiler only emits AGENTS.md/CLAUDE.md and now copilot-instructions.md). Please adjust the description strings (or wording) so the compile command doesn't claim it is generating install-time directories.
| def should_compile_copilot_instructions_md(target: TargetType) -> bool: | ||
| """Check if .github/copilot-instructions.md should be compiled. | ||
|
|
||
| Args: | ||
| target: The detected or configured target |
There was a problem hiding this comment.
This PR changes apm compile behavior by generating (and sometimes removing) .github/copilot-instructions.md. Per the docs-update rule, please update the Starlight docs (notably docs/src/content/docs/guides/compilation.md and the CLI reference) and the apm-guide skill resources (packages/apm-guide/.apm/skills/apm-usage/commands.md) to reflect the new output file and its cleanup/overwrite semantics.
08a2f6b to
950f1bc
Compare
Fixes #792.
Summary
.github/copilot-instructions.mdfrom global.apm/instructions/*.mdcontent duringapm compileminimalsemantics so it staysAGENTS.md-only instead of implicitly behaving likevscodeapplyTorules remain.github/copilot-instructions.mdfiles during cleanupTests
PYTHONPATH=src uv run pytest tests/unit/compilation/test_compile_target_flag.py tests/integration/test_compile_copilot_root_instructions.py tests/unit/core/test_target_detection.py tests/unit/integration/test_targets.py -xPYTHONPATH=src uv run pytest tests/unit tests/test_console.py -x