Repository navigation
feat: apm install -g deploys copilot instructions to ~/.copilot/copilot-instructions.md - #1619
Conversation
…opilot-instructions.md Issue #650: Copilot CLI reads a single file at user scope (~/.copilot/copilot-instructions.md), not individual *.instructions.md files. The copilot target previously listed 'instructions' in unsupported_user_primitives, making 'apm install -g' silently skip instruction primitives for copilot. Changes: - Add user_primitive_overrides field to TargetProfile (frozen dataclass) to allow per-primitive mapping overrides at user scope, applied after unsupported_user_primitives filtering in for_scope(user_scope=True). - Update copilot KNOWN_TARGETS entry: remove 'instructions' from unsupported_user_primitives; add user_primitive_overrides pointing to a new format_id 'copilot_user_instructions'. - Add _integrate_copilot_user_instructions() to InstructionIntegrator: strips YAML frontmatter from each source file and concatenates the bodies into ~/.copilot/copilot-instructions.md. - Update sync_for_target() to match on the single output file path when format_id == 'copilot_user_instructions'. - Update tests: test_scope.py, test_data_driven_dispatch.py, test_scope_install_uninstall.py, test_scope_integration.py to reflect that instructions are now supported at copilot user scope. - Add acceptance test: test_install_copilot_user_instructions.py. - Update targets-matrix.md documentation. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds user-scope support for Copilot instructions during apm install -g by introducing a user-scope primitive mapping override in TargetProfile and a new concat-based instruction deployment path that writes ~/.copilot/copilot-instructions.md. It updates unit tests to reflect the new behavior and documents the updated Copilot user-scope semantics.
Changes:
- Add
TargetProfile.user_primitive_overridesand apply it duringfor_scope(user_scope=True)resolution. - Implement
copilot_user_instructionssupport inInstructionIntegratorto concatenate instruction bodies into a singlecopilot-instructions.md. - Update/add tests and update the targets matrix documentation.
Show a summary per file
| File | Description |
|---|---|
src/apm_cli/integration/targets.py |
Adds user_primitive_overrides and updates Copilot’s user-scope instruction mapping. |
src/apm_cli/integration/instruction_integrator.py |
Adds concat integration + sync special-casing for Copilot user-scope instructions. |
tests/unit/integration/test_scope_integration.py |
Updates scope assertions to expect Copilot user-scope instructions support via concat format. |
tests/unit/integration/test_scope_install_uninstall.py |
Updates user-scope install/uninstall expectations to include .copilot/copilot-instructions.md. |
tests/unit/integration/test_data_driven_dispatch.py |
Updates dispatch tests to reflect user-scope Copilot instructions mapping override. |
tests/unit/install/test_install_copilot_user_instructions.py |
Adds acceptance-style tests for the new user-scope Copilot instruction concat behavior. |
tests/unit/core/test_scope.py |
Updates supports_at_user_scope and warning-message expectations for Copilot instructions. |
docs/src/content/docs/reference/targets-matrix.md |
Updates Copilot user-scope documentation to mention concatenation into ~/.copilot/copilot-instructions.md. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 6
| # Byte-identity check is not applicable for multi-source concat; | ||
| # go directly to collision detection. | ||
| if self.check_collision( | ||
| target_path, rel_path, managed_files, force, diagnostics=diagnostics | ||
| ): |
| bodies: list[str] = [] | ||
| for source_file in instruction_files: | ||
| content = source_file.read_text(encoding="utf-8") | ||
| body = self._strip_frontmatter(content).strip() | ||
| if body: | ||
| bodies.append(body) |
| Returns only the body text following the closing ``---`` delimiter. | ||
| If no frontmatter is present, returns the content unchanged. | ||
| """ | ||
| fm_match = re.match(r"^---\s*\n(.*?)\n---\s*\n?", content, re.DOTALL) |
| if self.user_primitive_overrides: | ||
| merged = dict(filtered) | ||
| merged.update(self.user_primitive_overrides) | ||
| filtered = merged |
| - hooks: `.github/hooks/<name>.json` | ||
| - generated: `.github/copilot-instructions.md` (compile output) | ||
| - **User scope.** Partial. `prompts` deploy under `~/.copilot/prompts/`; `instructions` are not supported at user scope. User-scope deploys land under `~/.copilot/`, not `~/.github/`. | ||
| - **User scope.** Partial. `prompts` deploy under `~/.copilot/prompts/`; `instructions` from all packages are concatenated into `~/.copilot/copilot-instructions.md` (Copilot CLI reads only that single file at user scope). User-scope deploys land under `~/.copilot/`, not `~/.github/`. |
| def test_multiple_instruction_files_concatenated(self): | ||
| """Multiple instruction files are concatenated into a single output file.""" | ||
| pkg_info = self._make_pkg( | ||
| { | ||
| "coding.instructions.md": ( | ||
| "---\napplyTo: '**/*.py'\n---\n\n# Python coding\n\nUse type hints.\n" | ||
| ), | ||
| "security.instructions.md": ( | ||
| "---\ndescription: Security rules\n---\n\n# Security\n\nSanitize inputs.\n" | ||
| ), | ||
| } | ||
| ) | ||
| copilot = KNOWN_TARGETS["copilot"] | ||
| user_profile = copilot.for_scope(user_scope=True) | ||
|
|
||
| self.integrator.integrate_instructions_for_target( |
…nce markers
- Fix multi-package collision: _integrate_copilot_user_instructions no
longer false-fires check_collision when the output file was written by
another package earlier in the same install session. The method now
embeds an APM-managed sentinel on first write; subsequent packages
detect the sentinel and append their provenance-marked section rather
than blocking.
- Add per-package HTML provenance markers so users and auditors can
attribute which package contributed which Copilot instructions:
...body...
- Fix _strip_frontmatter to handle Windows CRLF line endings (\r?\n).
- Fix for_scope() dynamic-root resolver path (user_root_resolver branch)
to apply user_primitive_overrides before returning, matching the static-
root path behavior. Latent bug: any future dynamic-root target that
sets both user_root_resolver and user_primitive_overrides would have
had its overrides silently ignored.
- Add ensure_path_within call in concat path for defense-in-depth.
- Add multi-package regression test and CRLF frontmatter stripping test.
- Add CHANGELOG entry framing the Copilot user-scope instructions story.
Co-authored-by: Copilot <[email protected]>
apm-review-panel advisoryPR: feat: apm install -g deploys copilot instructions to ~/.copilot/copilot-instructions.md Fixes applied in this session[blocking] Multi-package collision -- silent data loss (devx-ux-expert + 3 others) [recommended] Per-package provenance markers (supply-chain-security-expert, devx-ux-expert) Enables attribution audit and surgical section replacement on re-install. [recommended] for_scope() dynamic-root path skips user_primitive_overrides (python-architect) [nit] Windows CRLF frontmatter not stripped (python-architect, test-coverage-expert) [nit] ensure_path_within missing in concat path (supply-chain-security-expert) [process] CHANGELOG entry (oss-growth-hacker) [test] Multi-package regression test (test-coverage-expert) Deferred (out of scope)
MergeabilityAll Copilot inline findings folded. Lint: clean. Tests: 11/11 new pass, 2346/2346 existing pass. CI watch in progress. |
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]> Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]> Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]> Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]>
…ince supported - microsoft#1619 Signed-off-by: kilianpaquier <[email protected]> Co-authored-by: Copilot <[email protected]>
…ince supported - reverts #1619 (#2317) * fix(copilot): keep Copilot modular instructions split at user-scope since supported - #1619 Signed-off-by: kilianpaquier <[email protected]> Co-authored-by: Copilot <[email protected]> * fix(copilot): restore strip helper and align user-scope scan fixtures Keep `_strip_frontmatter` as a thin `_parse_frontmatter` wrapper so unit coverage of four-hyphen fences still passes after removing the concat path. Point policy/lifecycle unicode fixtures at modular `.copilot/instructions/*.instructions.md` now that user-scope no longer tracks the legacy concat file in generated_files. * fix(copilot): Mode B apm-spec-waiver for modular user-scope restore apm-spec-waiver: restore modular user-scope Copilot paths; no new OpenAPM-observable behaviour Co-authored-by: Copilot <[email protected]> * fix(copilot): align tests and docs with modular user-scope instructions (#2317) Panel-feedback follow-up for #2317, which restores modular Copilot instructions at user scope (~/.copilot/instructions/**/*.instructions.md, mirroring project-scope .github/instructions/) and clears generated_files for user-scope Copilot so the legacy concatenated copilot-instructions.md is no longer tracked there. Credit to @kilianpaquier for the original feature design. Required: - tests/integration/test_local_uninstall_alias_e2e.py: update the two global Copilot assertions that still pointed at the retired .copilot/copilot-instructions.md concat file to assert on the modular per-file .copilot/instructions/*.instructions.md paths instead, consistent with the project-scope pattern already used in the same file. - tests/integration/test_audit_primitive_contract.py: switch the user-scope tracked-metadata fixture path from .copilot/copilot-instructions.md to a modular .copilot/instructions/probe.instructions.md path. Soft (done): - CHANGELOG.md: [Unreleased] entry crediting @kilianpaquier for #2317. - docs/.../primitives-and-targets.md and docs/.../reference/cli/audit.md: replace stale 'prompts and instructions are project-scope only' / 'copilot-instructions.md aggregate' language with the modular user-scope instructions description. - src/apm_cli/integration/targets.py: short comment motivating user_supported="partial" for copilot now that instructions work at user scope but prompts/agents/skills/hooks/canvas still don't. - src/apm_cli/integration/instruction_integrator.py: harden the legacy-glob fallback in sync_for_target so Copilot's broad '*.instructions.md' legacy cleanup only applies to project scope (.github/instructions/, always APM-managed); user scope (.copilot/instructions/) now gets legacy_pattern=None, following the existing Claude/Windsurf/Kiro precedent, since other tools may also drop .instructions.md files into that shared user directory. - tests/unit/integration/test_scope_install_uninstall.py: new regression test proving a hand-authored file under .copilot/instructions/ survives an APM uninstall/sync cycle. Verified: full CI-mirror lint chain (ruff check, ruff format --check, pylint R0801, lint-auth-signals.sh) passes; targeted unit/integration suites pass (tests/unit/integration/ + test_audit_primitive_contract.py: 2181 passed); the two directly-touched e2e scenarios in test_local_uninstall_alias_e2e.py pass against a freshly built apm binary. The other two scenarios in that same e2e file (test_global_absolute_list_key_drives_update_and_uninstall, test_global_duplicate_alias_preserves_exact_path_survivor) fail in this sandbox both before and after this change -- confirmed pre-existing via git stash -- due to a tmp-dir/package-name collision ('Shared Package'/'Mixed Case Package' substrings leaking into CLI output paths) unrelated to this fix. Co-authored-by: Copilot <[email protected]> Co-authored-by: GitHub Copilot <[email protected]> * ci: give Lifecycle Smoke modest timeout headroom (#2317) The Lifecycle Smoke (Linux) job on fix/copilot-user-scope-instructions has been hitting the hard 6-minute job wall-clock timeout even though the required pytest selection itself passes cleanly (233 passed, 1 skipped in ~340s/5:40 on this tip). This is a CI wall-clock budget cascade, not a failing assertion: the 6-minute cap originally had headroom for checkout/setup/sync/cleanup plus test time, but as the required selection has grown it now routinely approaches ~5:40 of pytest time alone, leaving too little room for the surrounding job overhead. Raise lifecycle-smoke's timeout-minutes from 6 to 8 in .github/workflows/ci.yml and update the adjacent rationale comment to explain why. Keep tests/quality/test_ci_topology.py's LIFECYCLE_SMOKE_MAX_TIMEOUT_MINUTES guard in lockstep (6 -> 8) in the same commit so the topology contract stays green and still enforces a hard, tight hang bound. No change to the pytest selection expression, markers, required-check membership, E2E opt-in, or hermetic prohibitions. Credit to @kilianpaquier for the original work on #2317; this commit only addresses the CI timeout cascade observed on its tip. Co-authored-by: GitHub Copilot <[email protected]> --------- Signed-off-by: kilianpaquier <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Sergio Sisternes <[email protected]> Co-authored-by: GitHub Copilot <[email protected]>
Fixes #650.
TL;DR
apm install -gnow deploys instruction primitives for the Copilot target by concatenating all*.instructions.mdfiles into~/.copilot/copilot-instructions.md-- the single file Copilot CLI reads at user scope.Problem (WHY)
Copilot CLI reads only
~/.copilot/copilot-instructions.mdat user scope, not individual files in a subdirectory. The copilot target had"instructions"inunsupported_user_primitives, soapm install -gsilently skipped instruction primitives for Copilot users entirely.Approach (WHAT)
Rather than special-casing the copilot target in imperative code, the fix extends the data-driven
TargetProfilearchitecture:user_primitive_overrides: dict[str, PrimitiveMapping] | Nonefield lets targets swap a primitive's mapping at user scope.for_scope(user_scope=True)applies overrides after theunsupported_user_primitivesfilter.format_id = "copilot_user_instructions"triggers a concat transform instead of per-file deploy.Changes
targets.py: adduser_primitive_overridestoTargetProfile, apply infor_scope(), update copilot entryinstruction_integrator.py: new_integrate_copilot_user_instructions()concat method;sync_for_target()handles single output file cleanuptargets-matrix.mdupdatedValidation
All 15904 unit tests pass. Full lint chain clean (ruff + pylint R0801 + auth-signal).