Skip to content

fix(compile): emit and clean up copilot root instructions#930

Open
WilliamK112 wants to merge 1 commit intomicrosoft:mainfrom
WilliamK112:issue-792-copilot-root-instructions
Open

fix(compile): emit and clean up copilot root instructions#930
WilliamK112 wants to merge 1 commit intomicrosoft:mainfrom
WilliamK112:issue-792-copilot-root-instructions

Conversation

@WilliamK112
Copy link
Copy Markdown

Fixes #792.

Summary

  • generate .github/copilot-instructions.md from global .apm/instructions/*.md content during apm compile
  • preserve minimal semantics so it stays AGENTS.md-only instead of implicitly behaving like vscode
  • track Copilot root instructions in target metadata and target descriptions
  • clean up stale generated root instructions when switching away from Copilot output or when only scoped applyTo rules remain
  • preserve manually authored .github/copilot-instructions.md files during cleanup

Tests

  • 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 -x
  • PYTHONPATH=src uv run pytest tests/unit tests/test_console.py -x

Copilot AI review requested due to automatic review settings April 25, 2026 06:37
@WilliamK112
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md during apm compile (for Copilot-capable targets) and remove stale generated copies when switching targets or when only scoped applyTo rules remain.
  • Preserve minimal semantics by no longer remapping minimal to vscode in 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.

Comment on lines +398 to +400
# Keep the detected target intact so the compiler can preserve
# minimal-mode semantics (AGENTS.md only, no .github side outputs).
effective_target = detected_target
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +819 to +823
result.stats["copilot_root_instructions_unchanged"] = 1
return result

output_path.write_text(content, encoding="utf-8")
result.stats["copilot_root_instructions_written"] = 1
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +835 to +839
def _generate_copilot_root_instructions_content(
self,
instructions,
config: CompilationConfig,
) -> str:
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines 229 to 231
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/",
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +204 to +208
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
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot generated this review using guidance from repository custom instructions.
@WilliamK112 WilliamK112 force-pushed the issue-792-copilot-root-instructions branch from 08a2f6b to 950f1bc Compare April 27, 2026 01:06
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.

apm compile should emit .github/copilot-instructions.md (dogfood gap)

2 participants