[FEATURE] Per-dependency tag pattern so git semver ranges resolve against `@scope/name@version` release tags
Proposals are welcome before implementation. For substantive changes, wait for a responsible human maintainer to approve the scope and identify a review contact. An automated recommendation, label alone, or silence is not approval. See Contributing.
Is your feature request related to a problem? Please describe.
Monorepos that release with changesets or similar npm-style tooling tag each package as <package-name>@<version>, usually with an npm scope:
@acme/[email protected]
@acme/[email protected]
@acme/[email protected]
These tags work as exact literal refs:
dependencies:
apm:
- git: https://example.com/example-org/catalog.git
path: skills/foo
ref: '@acme/[email protected]'
They cannot be used with a semver range. With ref: '^1.2.0', the install fails even though matching tags exist:
No tags on example-org/catalog satisfy '^1.2.0'.
Tags considered: @acme/[email protected], @acme/[email protected], ... (and more).
What I found reading the source (v0.36.1 / main):
GitSemverResolveronly matches tags againstDEFAULT_TAG_PATTERNS(v{version},{name}--v{version},{name}-v{version}) plus the bare{version}fallback (src/apm_cli/deps/git_semver_resolver.py).- For virtual-subdirectory dependencies,
{name}is the last segment ofpath(git_semver_package_nameinsrc/apm_cli/install/helpers/ref_reuse.py), for examplefoo. It is never the published package name@acme/skill-foo. - The git-dependency call site does not pass
tag_patterns. Neither a consumer nor a producer can declare a different pattern for a git dependency. Thetag_patternsupport from #2366 covers marketplace dependencies only.
Who runs into this. Authors of monorepos with independently versioned packages that depend on sibling packages in the same repository. A typical case is a catalog where two plugins both depend on a shared skill:
[email protected] (released at commit A) -> skills/foo
[email protected] (released at commit B) -> skills/foo
If the plugins reference the shared skill by exact tag or by relative path, each plugin pins it to its own release commit. Installing both plugins then fails with incompatible immutable requirements. A semver range (ref: '^1.2.0') would avoid this: range edges are not part of the immutable-commit check, and the resolver picks one matching tag. With changesets-style tags, though, the range cannot resolve at all.
Today the remaining options are adding a second, APM-specific tag family to every release, or asking every consumer to add root replace rules.
Describe the solution you'd like
An optional tag_pattern field on git dependencies in object form. The git semver resolver uses it instead of the built-in patterns when it resolves a range:
- git: https://example.com/example-org/catalog.git
path: skills/foo
ref: '^1.2.0'
tag_pattern: '@acme/skill-foo@{version}'
This is mostly a manifest field plus passing it through. GitSemverResolver.resolve() already accepts tag_patterns, and build_tag_regex already builds the regex for a pattern.
For monorepos this also works centrally. The producer generates the field into its packages' own apm.yml files, on the edges between sibling packages. Consumers keep installing top-level packages by exact tag and never see or write tag_pattern.
How I would know it works:
ref: '^1.2.0'withtag_pattern: '@acme/skill-foo@{version}'resolves to the highest@acme/[email protected]tag that satisfies the range.- Tags of other packages in the same repository (
@acme/plugin-bar@...) are never candidates. - It also works for transitive edges declared in a dependency's
apm.yml, not only at the consumer root. - The lockfile records the constraint, the resolved tag and the commit, as it does for existing git semver resolutions.
apm installreplays the locked tag, andapm update/apm outdateduse the declared pattern. - The pinned-constraint policy check treats these as pinned ranges (see #3731 / #3775 for the literal-tag case).
Boundaries:
- Opt-in only. Without
tag_pattern, the default patterns and fallback behave exactly as today. Exact-tag, branch and SHA refs are unchanged. - The pattern must contain
{version}.{name}keeps its current meaning. All other text is literal and regex-escaped, so@and/in scoped names are safe. - Pre-release handling follows the existing semver range rules.
- Out of scope: how multiple requirements for the same dependency are merged. Today the shallowest/first-declared edge wins and ranges are not intersected. Non-overlapping ranges from two parents (e.g.
^0.2.0and^0.3.0) therefore resolve silently to one side. That may deserve its own issue, but this request does not depend on it.
Describe alternatives you've considered
- Producer-declared pattern in the dependency's own
apm.yml(e.g. a release-tag pattern next toversion). Range consumers would not need to know the tag layout, so this would be nicer. It raises a design question, though: apm would have to read the dependency's manifest before it knows which tag to fetch, e.g. from the parent's commit for same-repository dependencies or from the default branch otherwise. I would be equally happy with this if maintainers prefer it, possibly together with the per-dependency field as an explicit override. - Reusing the marketplace
build.tagPatternfor git dependencies. A single repo-wide pattern does not fit repositories where the tag prefix differs per package (@acme/skill-foo@...vs@acme/plugin-bar@...). apm cannot derive the full package name from the path basename or the manifestname. Primitives that are not marketplace entries would also have no pattern to inherit. - Exact literal tags (
ref: '@acme/[email protected]'). Reproducible, but they cannot express compatible updates. They causeincompatible immutable requirementsas soon as two parents from different release commits share a dependency. - A second tag family in a supported format (e.g.
foo-v1.2.0next to@acme/[email protected]). This works with{name}-v{version}today. It doubles the tagging work, though. Because{name}is only the path basename, packages with the same basename in different directories (e.g.skills/fooandagents/foo) would also collide in one tag family. - Same-repository relative
path:/git: parent. Good while developing on a branch because the child inherits the parent's ref. Two parents from different releases still pin the shared child to two different commits. - Consumer-side
replace. It can force one source for the shared dependency. It is still a candidate feature, though, and every consumer would have to maintain rules for something the producer could declare once.
Thanks for the well-researched proposal. The source reading checks out against v0.37.0: GitSemverResolver.resolve() accepts tag_patterns, but git dependencies only use the built-in v{version}, {name}--v{version} and {name}-v{version} patterns. The tag_pattern support from #2366 covers marketplace entries only.
Triage suggestion (advisory, not a maintainer decision): needs-design. The direction is sound, but this adds a manifest field, so a few points need agreement before code:
- Where the pattern lives: a consumer-side
tag_patternon the git dependency, a producer-declared pattern in the dependency's ownapm.yml, or both with a clear precedence. You already named the fetch-order question for the producer option. - Lockfile and replay: which fields record the pattern, constraint, tag and commit, so that
install,updateandoutdatedagree, including on transitive edges. - Policy: confirm that
require_pinned_constrainttreats these as pinned ranges. - Validation: reuse the existing marketplace pattern builder, so one owner validates
{version}and escapes literal text. - Spec and docs: the OpenAPM manifest text and the dependencies reference would need updating.
Related: #3648 (range grammar for registry ranges). Your acceptance criteria are a good basis for the done-when once the design is settled. Please wait for a maintainer to record scope and a review contact before implementing.
Generated by autopilot-issue-triage-worker. This comment is AI-generated and may contain errors.
Thanks for the triage.
-
Where the pattern lives: I'd start with the consumer-side
tag_patternon the git dependency. It is the smallest change, sinceGitSemverResolver.resolve()already acceptstag_patterns. A producer-declared pattern in the dependency's ownapm.ymlcould follow later, but it needs a decision on fetch order, so I'd keep it out of the first step. -
Lockfile and replay: From reading
main, the lockfile already recordsconstraintandresolved_tag, andreplay_locked_git_semverreuses the locked tag without needing a pattern. So the pattern may not need to be stored. One edge case needs a decision: if onlytag_patternchanges andrefstays the same, the constraint still matches the lock and the old tag would be replayed. Should a changed pattern invalidate the locked resolution? -
Policy:
_constraint_pinning.pyclassifies the declared constraint only (#3224), so a range such as^1.2.0already counts as pinned whatever pattern resolves it. I think a test would be enough here, no behavior change. I haven't run it. -
Validation: Happy to reuse
validate_tag_pattern/build_tag_regexfrommarketplace/tag_pattern.py, so one owner validates{version}and escapes literal text.