Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Marketplace dependency object entries in `apm.yml` and `plugin.json` now
resolve to concrete git refs during install, support optional semver-style
`version` constraints, and fail closed when resolution errors occur - by
@stbenjam (#1422)

### Breaking

- Reject string-form `@alias` dependency shorthand at parse time with a migration error; use object form with `alias:` instead -- by @prateek (#1301)
Expand Down
49 changes: 45 additions & 4 deletions docs/src/content/docs/consumer/manage-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,45 @@ parser. The supported forms:
| SSH with non-default user | `myuser@host:acme/repo.git` or `ssh://myuser@host/acme/repo.git` | Honors a non-`git` SSH user from the URL — useful for Enterprise Managed User (EMU) accounts or any server where the SSH login is not `git`. Username is validated against `^[a-zA-Z0-9_][a-zA-Z0-9_.+-]*$` (64-char cap); percent-encoded userinfo is rejected. The username is presentation-only and not part of dependency identity. |
| Local path | `./packages/shared` or `/abs/path` | Sibling package on disk. |
| Object form (git) | `{ git: <url>, path: <subpath>, ref: <ref>, alias: <name> }` | Custom directory name (`alias`), nested groups, monorepo subpaths, or anything the string forms cannot express. |
| Marketplace dict | `{ name: <plugin>, marketplace: <mkt>, version: <range> }` | Install a plugin from a registered marketplace. Optional `version` accepts a semver range (e.g. `~2.1.0`). Resolved to a concrete git ref at install time. |
| Registry shorthand | `owner/repo#^2.0.0` with a default registry configured | Routes dep through the default registry instead of git. Default may come from `apm.yml` or `~/.apm/config.json`. Requires `registries` experimental flag. |
| Registry object form | `{ id: owner/repo, version: ^2.0.0 }` | Explicit registry dep. `registry:` optional when a default registry is configured. Requires `registries` experimental flag. |

Object form in YAML:

Object form in YAML — three mutually exclusive keys select the variant
(`git`, `path`, or `marketplace`):

```yaml
dependencies:
apm:
# Git dep with sub-path
# Remote: git URL + optional sub-path, ref, alias
- git: https://gitlab.com/acme/coding-standards.git
path: instructions/security
ref: v2.0
alias: security

# Registry dep (experimental) — whole package via default registry
# Local: filesystem path (development only)
- path: ./packages/shared-skills

# Marketplace: resolved to a concrete git ref at install time
- name: sec-check
marketplace: acme-plugins

# Marketplace with version constraint (semver range)
- name: secrets-vault
marketplace: acme-plugins
version: "~2.1.0"

# Registry dep (experimental): whole package via default registry
- id: acme/code-review-prompts
version: ^2.0.0

# Registry dep — named registry, virtual sub-path
# Registry dep (experimental): named registry, virtual sub-path
- registry: corp-main
id: acme/prompt-library
path: prompts/review.prompt.md
version: 1.4.0

```

For private repos and non-GitHub hosts, see
Expand Down Expand Up @@ -168,6 +184,20 @@ SHAs. The lockfile pins the resolved commit either way, so two clones
running `apm install` get the same bytes -- but a branch ref will resolve
to a new SHA on the next `apm update`.

### Marketplace ref override

When installing from a marketplace via the CLI, append `#<ref>` to
override the marketplace entry's default `source.ref`:

```bash
apm install plugin@marketplace#v2.0.0
```

In `apm.yml`, use the `version` field in the marketplace object form.
Semver ranges and bare versions (e.g. `~2.1.0`, `^2.0`, `2.1.0`) are
resolved against git tags matching `{name}--v{version}` on the
marketplace repository. The highest matching tag is used.

### Pin a semver range

For git-source dependencies you can also pin a semver range as the ref.
Expand All @@ -190,6 +220,17 @@ lockfile alongside the resolved tag, so `apm install` on a fresh clone
replays the same tag deterministically. Only `apm update` (or legacy
`apm install --update`) or a manifest change re-resolves to a newer tag.

Marketplace object-form ranges use the marketplace package name in the tag
pattern:

```yaml
dependencies:
apm:
- name: secrets-vault
marketplace: acme-tools
version: "~2.1.0"
```

## Remove a dependency

1. Delete the entry from `apm.yml`.
Expand Down
33 changes: 28 additions & 5 deletions docs/src/content/docs/reference/manifest-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,29 @@ Monorepo sibling reference (`git: parent`):

The literal sentinel `git: parent` is valid only inside a transitively resolved package whose clone coordinates are known to the resolver. APM expands `parent` to the consumer's `host`, `repo_url`, and resolved `ref`, with `virtual_path` set from `path`. The lockfile records the **expanded** coordinates: `parent` MUST NOT appear as durable identity (`repo_url` / `source`). `path` is REQUIRED for `git: parent` and is normalised to a single relative path; absolute paths and `..` traversal are refused. `ref` and `alias` overrides are accepted; when `ref` is omitted the parent's resolved ref is inherited.

Marketplace dependency (resolved at install time):

```yaml
- name: sec-check
marketplace: acme-plugins

- name: secrets-vault
marketplace: acme-plugins
version: "~2.1.0"
```

| Field | Type | Required | Pattern / Constraint | Description |
|---|---|---|---|---|
| `name` | `string` | REQUIRED | `^[a-zA-Z0-9._-]+$` | Plugin identifier within the marketplace. |
| `marketplace` | `string` | REQUIRED | `^[a-zA-Z0-9._-]+$` | Registered marketplace name. |
| `version` | `string` | OPTIONAL | Semver range or exact version (e.g. `~2.1.0`, `^2.0`, `>=1.4`, `2.1.0`) | Version constraint resolved against git tags on the marketplace repository. When omitted the marketplace entry's default ref is used. |

The `marketplace` key is mutually exclusive with `git`, `path`, `registry`, and `id`; combining them raises a parse error. Unknown keys in a marketplace entry are rejected. During dependency resolution the resolver calls `resolve_marketplace_plugin()` to look up the plugin in the marketplace's `marketplace.json` and replace the entry with a concrete git reference (owner/repo, ref, and optional virtual path).

When `version` is specified and is a semver range or bare version number (e.g. `~2.1.0`, `^2.0`, `2.1.0`), the resolver lists git tags on the marketplace repository matching the `{name}--v{version}` convention, filters to those satisfying the constraint, and resolves to the highest matching tag. If no tag satisfies an explicit semver range, resolution fails with a `NoMatchingVersionError`. A bare version with no matching tag falls back to using the value as a raw git ref. Pre-release versions (e.g. `2.0.0-beta.1`) are excluded from semver-range resolution; target them explicitly as raw git refs. When `version` is a raw git ref (e.g. `v2.0.0`, `main`, or a commit SHA), it is used as a direct ref override without tag resolution.

Resolution failures stop the install instead of silently skipping the dependency. The lockfile records the **resolved** coordinates and pinned commit, not the marketplace placeholder. Unresolved marketplace dependencies cannot compute install paths or serialize back to `apm.yml`.

Registry dependency (whole package or virtual sub-path):

```yaml
Expand All @@ -408,19 +431,19 @@ Registry dependency (whole package or virtual sub-path):
version: ^2.0.0

# Whole package routed to a named registry
- registry: jf-skills # OPTIONAL — defaults to the effective default registry
id: acme/toolkit # REQUIRED — owner/repo identity at the registry
version: ^2.0.0 # REQUIRED — opaque version selector (semver when supported)
- registry: jf-skills # OPTIONAL - defaults to the effective default registry
id: acme/toolkit # REQUIRED - owner/repo identity at the registry
version: ^2.0.0 # REQUIRED - opaque version selector (semver when supported)

# Virtual package (sub-path inside a published package)
- registry: jf-skills
id: acme/prompt-pack
path: prompts/review.prompt.md # OPTIONAL — omit to install the whole package
path: prompts/review.prompt.md # OPTIONAL - omit to install the whole package
version: 1.4.0
alias: review # OPTIONAL
```

`id:` (or `registry:`) and `git:` are mutually exclusive on the same entry. `version:` MUST be a non-empty string — opaque selectors such as `stable`, `main`, or commit pins are valid; semver ranges (`^1.2.3`) are interpreted as ranges when the registry publishes semver-tagged versions. When `registry:` is omitted, a default registry MUST be configured — in project `apm.yml` or via `registry.<name>.default true` in `~/.apm/config.json`; APM hard-fails otherwise.
`id:` (or `registry:`) and `git:` are mutually exclusive on the same entry. `version:` MUST be a non-empty string - opaque selectors such as `stable`, `main`, or commit pins are valid; semver ranges (`^1.2.3`) are interpreted as ranges when the registry publishes semver-tagged versions. When `registry:` is omitted, a default registry MUST be configured - in project `apm.yml` or via `registry.<name>.default true` in `~/.apm/config.json`; APM hard-fails otherwise.

#### 4.1.3. Virtual Packages

Expand Down
59 changes: 55 additions & 4 deletions packages/apm-guide/.apm/skills/apm-usage/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,23 @@ both protocols.

## Object form (complex cases)

Use object form when you need a custom install directory name. The legacy
string suffix `@alias` is not supported; write `alias:` explicitly instead so
`@` remains reserved for git usernames and version syntax.
Use the object form when the string shorthand cannot express what you need:
nested-group repos with virtual paths, custom SSH ports, local path deps,
aliases, or marketplace dependencies.

Three mutually exclusive keys select the form: `git`, `path`, or `marketplace`.

The legacy string suffix `@alias` is not supported; write `alias:` explicitly
instead so `@` remains reserved for git usernames and version syntax.

### Remote (`git`)

| Field | Required | Description |
|-------|----------|-------------|
| `git` | REQUIRED | Clone URL (HTTPS, SSH, or FQDN shorthand). The literal `parent` inherits the consuming package's repo. |
| `path` | OPTIONAL | Subdirectory or file within the repo (virtual package). |
| `ref` | OPTIONAL | Branch, tag, or commit SHA. |
| `alias` | OPTIONAL | Install under a custom directory name (`^[a-zA-Z0-9._-]+$`). |

```yaml
- git: https://gitlab.com/acme/repo.git
Expand All @@ -132,8 +146,45 @@ string suffix `@alias` is not supported; write `alias:` explicitly instead so

- git: ssh://git@bitbucket.example.com:7999/project/repo.git # custom SSH port
ref: v1.0
```

### Local (`path`)

| Field | Required | Description |
|-------|----------|-------------|
| `path` | REQUIRED | Filesystem path (must start with `./`, `../`, `/`, or `~/`). |

Local-path deps inside another local package resolve relative to that
package's directory, not the project root.

```yaml
- path: ./packages/my-skills
```

### Marketplace (`name` + `marketplace`)

| Field | Required | Description |
|-------|----------|-------------|
| `name` | REQUIRED | Plugin identifier within the marketplace (`^[a-zA-Z0-9._-]+$`). |
| `marketplace` | REQUIRED | Registered marketplace name (`^[a-zA-Z0-9._-]+$`). |
| `version` | OPTIONAL | Semver range or exact version (e.g. `~2.1.0`, `^2.0`, `>=1.4`, `2.1.0`). Resolved against `{name}--v{version}` git tags on the marketplace repo. |

During resolution, marketplace entries are looked up in the marketplace's
`marketplace.json` and replaced with concrete git coordinates. When `version`
is a semver range or bare version number, the resolver lists git tags
matching `{name}--v{version}`, filters by the constraint, and picks the
highest matching tag. Raw git refs (e.g. `v2.0.0`, `main`) bypass tag
resolution and override the source ref directly. The lockfile records the
resolved ref, not the marketplace placeholder. Unknown keys in a marketplace
entry are rejected.

```yaml
- name: sec-check
marketplace: acme-plugins

- path: ./packages/my-skills # local only
- name: secrets-vault
marketplace: acme-plugins
version: "~2.1.0"
```

## Registry-sourced APM dependencies (experimental)
Expand Down
111 changes: 111 additions & 0 deletions src/apm_cli/deps/apm_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
apm_modules_dir: Path | None = None,
download_callback: DownloadCallback | None = None,
max_parallel: int | None = None,
auth_resolver: object | None = None,
):
"""Initialize the resolver with maximum recursion depth.

Expand All @@ -78,6 +79,7 @@ def __init__(
``_DEFAULT_RESOLVE_PARALLEL`` (4). Set to ``1`` ONLY
for parity-testing against the legacy sequential path
-- this is a diagnostic knob, not a user toggle.
auth_resolver: Optional auth resolver for marketplace dependency resolution.
"""
self.max_depth = max_depth
self._apm_modules_dir: Path | None = apm_modules_dir
Expand Down Expand Up @@ -111,6 +113,7 @@ def __init__(
# acquires the lock -- the overhead is negligible and the
# symmetry simplifies reasoning.
self._download_lock = threading.Lock()
self._auth_resolver = auth_resolver
self._max_parallel = self._resolve_max_parallel(max_parallel)

@staticmethod
Expand Down Expand Up @@ -221,6 +224,9 @@ def resolve_dependencies(self, project_root: Path) -> DependencyGraph:
circular_dependencies=circular_deps,
)

for error in dependency_tree.resolution_errors:
graph.add_error(error)

return graph

def _remote_parent_eligible(self, parent_dep: DependencyReference) -> bool:
Expand Down Expand Up @@ -274,6 +280,91 @@ def expand_parent_repo_decl(
local_path=None,
)

def _resolve_marketplace_dep(self, dep_ref: DependencyReference) -> DependencyReference:
"""Resolve a marketplace dependency to a concrete DependencyReference.

Uses :func:`resolve_marketplace_plugin` to look up the plugin in the
registered marketplace and returns a resolved git-backed reference.
Prefers the structured ``dependency_reference`` from the resolution
when available (GitLab-class hosts, in-marketplace subdirectory
plugins) over parsing the canonical string.

Args:
dep_ref: An unresolved marketplace DependencyReference.

Returns:
A concrete (non-marketplace) DependencyReference.

Raises:
MarketplaceNotFoundError: Marketplace is not registered.
PluginNotFoundError: Plugin not found in the marketplace.
MarketplaceFetchError: Network/auth error fetching marketplace data.
ValueError: Invalid marketplace or plugin configuration.
"""
from apm_cli.marketplace.resolver import resolve_marketplace_plugin

resolution = resolve_marketplace_plugin(
dep_ref.marketplace_plugin_name,
dep_ref.marketplace_name,
version_spec=dep_ref.marketplace_version_spec,
auth_resolver=self._auth_resolver,
warning_handler=_logger.warning,
)
if resolution.dependency_reference is not None:
return resolution.dependency_reference
return DependencyReference.parse(resolution.canonical)

def _resolve_marketplace_or_record_error(
self,
dep_ref: DependencyReference,
tree: DependencyTree,
context: str,
) -> DependencyReference | None:
"""Try to resolve a marketplace dep; record an error on the tree on failure.

Catches known marketplace exceptions and records them as resolution
errors. Unknown exceptions propagate so programmer errors are not
silently swallowed.

Args:
dep_ref: Unresolved marketplace dependency.
tree: The dependency tree to record errors on.
context: Human-readable context for error messages
(e.g. ``"required by owner/repo"``).

Returns:
Resolved DependencyReference on success, ``None`` on known failure.
"""
from apm_cli.marketplace.errors import (
BuildError,
MarketplaceFetchError,
MarketplaceNotFoundError,
PluginNotFoundError,
)

try:
return self._resolve_marketplace_dep(dep_ref)
except (
MarketplaceNotFoundError,
PluginNotFoundError,
MarketplaceFetchError,
BuildError,
ValueError,
) as exc:
_logger.debug(
"Marketplace resolution failed for %s@%s: %s",
dep_ref.marketplace_plugin_name,
dep_ref.marketplace_name,
exc,
)
tree.resolution_errors.append(
f"Failed to resolve marketplace dependency "
f"'{dep_ref.marketplace_plugin_name}' from "
f"marketplace '{dep_ref.marketplace_name}'"
f"{f' ({context})' if context else ''}: {exc}"
)
return None

def build_dependency_tree(self, root_apm_yml: Path) -> DependencyTree:
"""
Build complete tree of all dependencies and sub-dependencies.
Expand Down Expand Up @@ -322,6 +413,12 @@ def build_dependency_tree(self, root_apm_yml: Path) -> DependencyTree:
"specify an explicit repository URL. "
"The git: parent form is only valid for transitive dependencies."
)
if dep_ref.is_marketplace:
resolved = self._resolve_marketplace_or_record_error(dep_ref, tree, "")
if resolved is not None:
dep_ref = resolved
else:
continue
Comment thread
stbenjam marked this conversation as resolved.
Resolved
processing_queue.append((dep_ref, 1, None, False))
queued_keys.add(dep_ref.get_unique_key())

Expand All @@ -334,6 +431,12 @@ def build_dependency_tree(self, root_apm_yml: Path) -> DependencyTree:
"specify an explicit repository URL. "
"The git: parent form is only valid for transitive dependencies."
)
if dep_ref.is_marketplace:
resolved = self._resolve_marketplace_or_record_error(dep_ref, tree, "")
if resolved is not None:
dep_ref = resolved
else:
continue
key = dep_ref.get_unique_key()
if key not in queued_keys:
processing_queue.append((dep_ref, 1, None, True))
Expand Down Expand Up @@ -467,6 +570,14 @@ def build_dependency_tree(self, root_apm_yml: Path) -> DependencyTree:
for sub_dep in sub_dependencies:
if sub_dep.is_parent_repo_inheritance:
sub_dep = self.expand_parent_repo_decl(node.dependency_ref, sub_dep)
if sub_dep.is_marketplace:
resolved = self._resolve_marketplace_or_record_error(
sub_dep, tree, f"required by {node.dependency_ref.repo_url}"
)
if resolved is not None:
sub_dep = resolved
else:
continue
Comment thread
stbenjam marked this conversation as resolved.
Resolved
# Avoid infinite recursion by checking if we're already processing this dep
# Use O(1) set lookup instead of O(n) list comprehension
if sub_dep.get_unique_key() not in queued_keys:
Expand Down
Loading
Loading