Repository navigation
Description
Follow-up from #781 (which fixed the immediate ordering bug behind #780).
Problem
detect_package_type() in src/apm_cli/models/validation.py is a positional-priority if/elif cascade that conflates three concerns:
- Evidence gathering -- did we see
apm.yml,SKILL.md,hooks/*.json,plugin.json,agents/skills/commands/? - Classification -- which
PackageTypeenum value to assign. - Normalization-strategy selection -- which downstream synthesizer to run (e.g.
normalize_plugin_directoryforMARKETPLACE_PLUGIN).
The cascade's first-match-wins semantics means every new bundled-format introduces a potential ordering bug. #780 was the latest one; the next one is just a matter of time.
Proposed shape
Move to a composition model:
FormatDetectorinterface, one impl per format:ApmYmlDetector,SkillMdDetector,HookJsonDetector,ClaudePluginDetector. Each returnsOptional[FormatEvidence]independent of the others.PackageFormatRegistryruns all detectors and produces aDetectionReport(set of evidences -- not a singlePackageType).NormalizationPlannerreads the report and decides which normalizers to run. Mixed packages become first-class (e.g. a Claude plugin that legitimately ships hooks runs both the plugin synthesizer AND the hooks pass-through, instead of being shoehorned into one classification).
The DetectionEvidence dataclass + gather_detection_evidence() helper landed in #781 are intentionally a step in this direction -- they decouple the evidence scan from classification so observability code can already use the richer payload.
Benefits
- New formats are additive -- no ordering bugs possible.
- Mixed packages are first-class (today's implicit "
MARKETPLACE_PLUGINhappens to also handle hooks" becomes explicit). - The
DetectionReportdoubles as the observability payload (verbose detection traces, deploy-summary labels, near-miss warnings). - The classification logic stops being a positional puzzle.
Cost
Medium -- touches models/validation.py, install/sources.py, plus all consumers of PackageType (lockfile recording, install summary, drift detection). Should land behind a feature flag for one release if downstream test churn is high.
Out of scope for this issue
- Tightening
_has_hook_jsonto only count files matching the actual Claude hooks schema (today: any*.jsoninhooks/). - Introducing an explicit
MIXEDPackageType-- theDetectionReportmodel makes the enum redundant for mixed cases.
Related
- Install silently drops skills/agents/commands when package also ships hooks/*.json #780 (the bug that surfaced this design debt)
- fix(install): MARKETPLACE_PLUGIN beats HOOK_PACKAGE in detection cascade (#780) #781 (the surgical fix that ships now, with this refactor queued behind it)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Apr 26, 2026
Triage decision
accept
Proposed labels
Milestone
0.9.4
Suggested next action
Implement the three-concern separation in
detect_package_type()-- evidence gathering, classification, and normalization-strategy selection -- with full unit test coverage for each concern boundary.Suggested issue comment
Per-lens notes (collapsed)
DevX UX Expert -- User-Need Reviewer
This is an internal refactor with indirect user benefit: a more explicit and testable detection path reduces the risk of regressions like bug #780. The user task is "have APM correctly identify package types"; this refactor serves that by making the detection logic maintainable and auditable. Well-aligned with APM's goal of reliable package type support across diverse package structures.
Supply Chain Security Expert -- Risk-Surface Reviewer
No risk-surface implication.
detect_package_type()is a classification utility; the refactor does not change the security enforcement boundary. Package type misclassification is a correctness bug, not a supply-chain attack surface in this context.OSS Growth Hacker -- Contributor-Tone Reviewer
Not activated -- danielmeppiel is a core maintainer with extensive project ownership; warmth tuning for a new contributor is not needed.
Python Architect -- Architecture Reviewer
The three-concern separation is the right design. The key implementation risk is that the existing if/elif has implicit evaluation-order dependencies that may not be obvious until the refactor surfaces them. Recommend explicit documentation of precedence rules in the new design. A Strategy pattern (or a simple StrategySelector function) keeps the abstraction at the right level for the current codebase size.
status/acceptedis appropriate -- the design is sufficiently specified by the issue body.Doc Writer -- Documentation Reviewer
Not activated -- this is a pure internal refactor with no user-visible API or behavior change; no new documentation pages are needed.
APM CEO -- Triage Arbiter
Straightforward internal refactor following a completed bug fix. Accept at priority/low for 0.9.4: the fix is not urgent but improves long-term maintainability and reduces regression risk as new package types are added. No theme label needed -- pure infra (area/cli + area/testing) with no product surface implication.
{ "decision": "accept", "decision_detail": "", "theme": null, "areas": ["area/cli", "area/testing"], "type": "type/refactor", "status": "status/accepted", "priority": "priority/low", "preserved_labels": [], "milestone": "0.9.4", "next_action": "Implement the three-concern separation in detect_package_type() with full unit test coverage for each concern boundary.", "comment_markdown": "Good follow-up framing. PR #781 fixed the immediate ordering bug, but the underlying if/elif cascade still conflates three concerns, making it fragile to extend.\n\nThe proposed separation is sound: gather evidence first (which files/dirs are present), then classify to a `PackageType`, then select a normalization strategy. This makes each concern independently testable and makes adding a new package type explicit rather than positional.\n\nA few things to keep in mind during implementation:\n\n- The refactor touches `detect_package_type()` which is called at every package load. Include regression tests for the existing package types (apm-native, skill-only, plugin, etc.) to confirm the refactor does not change behavior.\n- Document the new precedence rules explicitly (as code comments or a docstring) so the next contributor does not have to reverse-engineer them.\n- If the Strategy pattern introduces an abstract base class or a registry, keep it in the same module for now -- premature cross-module extraction is out of scope for this ticket.\n\nHappy to review a PR when ready." }refactor(models): separate package-format detection into composition …