Skip to content

feat: apm install -g deploys copilot instructions to ~/.copilot/copilot-instructions.md - #1619

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel/650-install-g-user-instr
Jun 2, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel/650-install-g-user-instr

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Fixes #650.

TL;DR

apm install -g now deploys instruction primitives for the Copilot target by concatenating all *.instructions.md files into ~/.copilot/copilot-instructions.md -- the single file Copilot CLI reads at user scope.

Problem (WHY)

Copilot CLI reads only ~/.copilot/copilot-instructions.md at user scope, not individual files in a subdirectory. The copilot target had "instructions" in unsupported_user_primitives, so apm install -g silently 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 TargetProfile architecture:

  1. A new user_primitive_overrides: dict[str, PrimitiveMapping] | None field lets targets swap a primitive's mapping at user scope.
  2. for_scope(user_scope=True) applies overrides after the unsupported_user_primitives filter.
  3. A new format_id = "copilot_user_instructions" triggers a concat transform instead of per-file deploy.

Changes

  • targets.py: add user_primitive_overrides to TargetProfile, apply in for_scope(), update copilot entry
  • instruction_integrator.py: new _integrate_copilot_user_instructions() concat method; sync_for_target() handles single output file cleanup
  • Tests: 9 new acceptance tests + 4 existing tests updated
  • Docs: targets-matrix.md updated

Validation

All 15904 unit tests pass. Full lint chain clean (ruff + pylint R0801 + auth-signal).

…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_overrides and apply it during for_scope(user_scope=True) resolution.
  • Implement copilot_user_instructions support in InstructionIntegrator to concatenate instruction bodies into a single copilot-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

Comment on lines +256 to +260
# 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
):
Comment on lines +243 to +248
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)
Comment on lines +358 to +361
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/`.
Comment on lines +131 to +146
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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

apm-review-panel advisory

PR: feat: apm install -g deploys copilot instructions to ~/.copilot/copilot-instructions.md
Panel: python-architect | cli-logging-expert | devx-ux-expert | supply-chain-security-expert | oss-growth-hacker | doc-writer | test-coverage-expert | auth-expert (inactive)
CEO verdict: ship-with-changes -- all blocking and recommended items folded in commit fcdbfbb


Fixes applied in this session

[blocking] Multi-package collision -- silent data loss (devx-ux-expert + 3 others)
instruction_integrator.py -- _integrate_copilot_user_instructions called check_collision which always blocked the second package in a session (file written by pkg-1 not in managed_files for pkg-2). Fixed: first write now stamps an APM-managed sentinel; subsequent writes detect it and append their section instead of colliding. All 11 acceptance tests pass.

[recommended] Per-package provenance markers (supply-chain-security-expert, devx-ux-expert)
Each package's contribution is now wrapped:

...body...

Enables attribution audit and surgical section replacement on re-install.

[recommended] for_scope() dynamic-root path skips user_primitive_overrides (python-architect)
targets.py -- applied the override merge in the user_root_resolver branch before early return, matching the static-root path. Latent correctness bug for future targets that combine both fields.

[nit] Windows CRLF frontmatter not stripped (python-architect, test-coverage-expert)
instruction_integrator.py -- regex changed from \n to \r?\n. New test: test_strip_frontmatter_strips_crlf_line_endings.

[nit] ensure_path_within missing in concat path (supply-chain-security-expert)
Added for defense-in-depth pattern consistency.

[process] CHANGELOG entry (oss-growth-hacker)
Added to [Unreleased] > Fixed framing the Copilot user-scope instructions narrative.

[test] Multi-package regression test (test-coverage-expert)
test_multi_package_instructions_all_concatenated -- installs two packages sequentially, asserts both packages' content is present in the output file.


Deferred (out of scope)

  • User consent/preview before first write (supply-chain-security-expert) -- requires an interactive confirmation flow; tracked separately.
  • Link resolution in concat path (python-architect) -- relative links are meaningless at user scope; no resolution needed. Comment added in code for clarity.
  • resolve_links call -- deferred with code comment; user-scope instructions have no meaningful link targets.

Mergeability

All Copilot inline findings folded. Lint: clean. Tests: 11/11 new pass, 2346/2346 existing pass. CI watch in progress.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 600910d into main Jun 2, 2026
15 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel/650-install-g-user-instr branch June 2, 2026 18:04
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 1, 2026
…ince supported - microsoft#1619

Signed-off-by: kilianpaquier <[email protected]>
Signed-off-by: kilianpaquier <[email protected]>
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 8, 2026
…ince supported - microsoft#1619

Signed-off-by: kilianpaquier <[email protected]>
Signed-off-by: kilianpaquier <[email protected]>
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 19, 2026
…ince supported - microsoft#1619

Signed-off-by: kilianpaquier <[email protected]>
Signed-off-by: kilianpaquier <[email protected]>
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 19, 2026
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 19, 2026
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Aug 28, 2026
kilianpaquier added a commit to kilianpaquier/apm that referenced this pull request Sep 1, 2026
Sergio Sisternes (sergio-sisternes-epam) pushed a commit to kilianpaquier/apm that referenced this pull request Oct 1, 2026
Daniel Meppiel (danielmeppiel) pushed a commit that referenced this pull request Oct 2, 2026
…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]>
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.

[FEATURE] Copilot CLI user-scope instructions: can apm install -g write copilot-instructions.md

2 participants