Skip to content

Replace monolithic if-chains with target-driven INTEGRATION_DISPATCH registry#489

Closed
Copilot wants to merge 6 commits intomainfrom
copilot/fix-opencode-unconditional-writes
Closed

Replace monolithic if-chains with target-driven INTEGRATION_DISPATCH registry#489
Copilot wants to merge 6 commits intomainfrom
copilot/fix-opencode-unconditional-writes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Description

--target opencode unconditionally writes to .github/prompts/ and .github/agents/, creating a .github/ directory the user never requested. Same class of bug affects cursor/opencode integrations that ran without flag-level gating.

Root cause: _integrate_package_primitives() used per-target boolean flags (integrate_vscode, integrate_claude, integrate_opencode) with hardcoded if-chains. Prompts, .github/agents, cursor, and opencode integrations ran unconditionally because guards were missing or incomplete. This monolithic approach doesn't scale — adding a target or primitive means editing install.py's if-chain.

Fix — declarative target-driven dispatch architecture:

  • INTEGRATION_DISPATCH registry in targets.py: a dict mapping (target_name, primitive_name)(integrator_key, method_name, log_dir). Single source of truth for all routing.
  • integrate_package_for_targets() in targets.py: centralized dispatcher that loops active TargetProfile instances and dispatches per-primitive via the registry. One loop, no if-chains.
  • _integrate_package_primitives() in install.py: simplified to a thin adapter accepting targets= (list of TargetProfile) instead of boolean flags, delegating to the centralized dispatcher.

Adding a new target or primitive now requires:

  1. A KNOWN_TARGETS entry (already existed)
  2. An INTEGRATION_DISPATCH entry
  3. The integrator method it references

No touching install.py.

# Before: monolithic if-chains in install.py
if integrate_vscode:
    prompt_result = prompt_integrator.integrate_package_prompts(...)
if integrate_claude:
    agent_result = agent_integrator.integrate_package_agents_claude(...)
# ... 13 more if-blocks

# After: declarative registry + single dispatch loop
INTEGRATION_DISPATCH = {
    ("copilot", "prompts"): ("prompt_integrator", "integrate_package_prompts", ".github/prompts/"),
    ("claude", "agents"):   ("agent_integrator", "integrate_package_agents_claude", ".claude/agents/"),
    # ...
}

for target in targets:
    for primitive in target.primitives:
        entry = INTEGRATION_DISPATCH.get((target.name, primitive))
        integrator.method(package_info, project_root, ...)

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

11 new tests added:

  • 7 target-gating regression tests (opencode-only skips .github/, opencode-only calls its integrators, cursor-only skips all other targets, copilot-only skips cursor/opencode, empty targets returns zeros, etc.)
  • 2 registry validation tests (test_every_target_primitive_has_dispatch_entry, test_dispatch_entries_reference_valid_methods) to catch gaps at test time
  • 2 dispatcher tests (single target dispatch, all-targets dispatch verifying every registry entry fires once)

Copilot AI and others added 2 commits March 30, 2026 12:44
Agent-Logs-Url: https://github.com/microsoft/apm/sessions/ac5a8b5e-a4fe-469b-be63-e307ca8b62b9

Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
Add integrate_cursor flag alongside existing integrate_vscode,
integrate_claude, integrate_opencode. Guard all target-specific
integrations in _integrate_package_primitives():

- .github/prompts/ and .github/agents/ behind integrate_vscode
- .cursor/rules/, .cursor/agents/, .cursor/hooks behind integrate_cursor
- .opencode/agents/ and .opencode/commands/ behind integrate_opencode

Fixes --target opencode creating .github/ directory.

Agent-Logs-Url: https://github.com/microsoft/apm/sessions/ac5a8b5e-a4fe-469b-be63-e307ca8b62b9

Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with target opencode creating .github directory Guard all target-specific integrations behind proper flags Mar 30, 2026
Copilot AI requested a review from danielmeppiel March 30, 2026 12:54
@danielmeppiel
Copy link
Copy Markdown
Collaborator

@copilot think of a better and more scalable architecture which separates concerns. We do have a BaseIntegrator class. Why not think of a CopilotIntegrator, CursorIntegrator etc which manage this? multiplying checkpoints in install.py won't scale and is monolithic. Rethink architectural approach with solid design patterns so that we reduce failure points as much as possible.

Copilot AI and others added 3 commits March 30, 2026 15:03
Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1515287c-ba20-4681-8c88-a643718c2f1e

Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
Introduce INTEGRATION_DISPATCH registry in targets.py that maps
(target_name, primitive_name) to (integrator_key, method_name, log_dir).

integrate_package_for_targets() loops active TargetProfiles and
dispatches to the correct integrator method for each supported
primitive. No if-chains needed — adding a target/primitive means
adding a registry entry.

_integrate_package_primitives() in install.py now accepts targets=
(list of TargetProfile) instead of boolean flags and delegates to
the centralized dispatcher.

Fixes --target opencode creating .github/ and similar cross-target leaks.

Agent-Logs-Url: https://github.com/microsoft/apm/sessions/1515287c-ba20-4681-8c88-a643718c2f1e

Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 30, 2026

@copilot think of a better and more scalable architecture which separates concerns. We do have a BaseIntegrator class. Why not think of a CopilotIntegrator, CursorIntegrator etc which ...

Redesigned the architecture in 2ac3e9b. Instead of multiplying boolean flags and if-chains in install.py, the new approach uses:

  1. INTEGRATION_DISPATCH registry in targets.py — a declarative dict mapping (target_name, primitive_name) to (integrator_key, method_name, log_dir). This is the single source of truth for routing.

  2. integrate_package_for_targets() — a centralized dispatcher that loops active TargetProfile instances and dispatches per-primitive via the registry. One loop, no if-chains.

  3. _integrate_package_primitives() simplified to a thin adapter accepting targets= (list of TargetProfile) instead of boolean flags.

Adding a new target or primitive now requires:

  1. A KNOWN_TARGETS entry (already existed)
  2. An INTEGRATION_DISPATCH entry (new)
  3. The integrator method it references

No touching install.py. Tests include registry completeness validation (test_every_target_primitive_has_dispatch_entry) and method existence checks (test_dispatch_entries_reference_valid_methods) to catch gaps at test time.

Copilot AI changed the title Guard all target-specific integrations behind proper flags Replace monolithic if-chains with target-driven INTEGRATION_DISPATCH registry Mar 30, 2026
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.

[BUG] --target opencode still writes to .github/prompts/ and .github/agents

2 participants