# SwiftPM

Recommend AXM extensions from a Swift Package Manager package and target SwiftPM packages from an extension.

AXM reads Swift extension metadata from an `agent-extensions.json` sidecar at
the package root — next to `Package.swift`. This is the
[two-way linking](/docs/package-ecosystems/overview) model applied to the Swift
Package Manager ecosystem. SwiftPM has no manifest field for arbitrary metadata,
so a sidecar file carries the recommendation.

## Recommend extensions from a package

Add an `agent-extensions.json` file at the package root with an
`agentExtensions` array. Each entry is an extension reference
(`@owner/<type>/<name>`):

```jsonc
// agent-extensions.json
{
  "$schema": "https://axm.sh/schemas/agent-extensions.schema.json",
  "agentExtensions": [{ "ref": "@examples/packs/swift-spm-tinyflags" }],
}
```

SwiftPM resolves packages from source checkouts, so committing
`agent-extensions.json` beside `Package.swift` makes it available to consumers
in their checkout.

Keep recommendations **identity-only** — omit `versionRange`. AXM resolves the
reference to the newest matching extension version and pins it in the user's
`axm.lock`. Prefer recommending a single **pack** so you keep one stable
reference while its contents evolve.

Add a semver `versionRange` only when your package genuinely pairs with a
bounded major line of the extension:

```jsonc
{
  "agentExtensions": [
    {
      "ref": "@examples/packs/swift-spm-tinyflags",
      "versionRange": "^1.0.0",
    },
  ],
}
```

## Target SwiftPM packages from an extension

On the extension manifest (`skill.json`, `pack.json`, `subagent.json`, …), add a
`packages` array with a Swift [purl](https://github.com/package-url/purl-spec).
The Swift purl type is `swift`, and the host and path of the package's source
repository form the namespace and name:

```jsonc
// pack.json
{
  "packages": [
    { "purl": "pkg:swift/example.com/agentxm/example-tinyflags-swift" },
  ],
}
```

### Version ranges

Default to identity-only. Add a [VERS](https://github.com/package-url/vers-spec)
`versionRange` with the `swift` scheme only when the extension depends on
package APIs introduced or removed in a known range:

```jsonc
{
  "packages": [
    {
      "purl": "pkg:swift/example.com/agentxm/example-tinyflags-swift",
      "versionRange": "vers:swift/>=0.1.0|<1.0.0",
    },
  ],
}
```

## Official status

When the SwiftPM package recommends an extension through the AgentXM Registry
**and** that extension names the package as a companion via its purl, AXM
derives **official** status for the pair — no extra flag. See
[Official extensions](/docs/package-ecosystems/overview#official-extensions).

## Reference fixture

The
[`swift-spm-lib`](https://github.com/agentxm/polyglot-examples/tree/main/swift-spm-lib)
and
[`swift-spm-app`](https://github.com/agentxm/polyglot-examples/tree/main/swift-spm-app)
directories in `polyglot-examples` are the working fixtures for everything
above. The package publishes a TinyFlags companion pack and recommends it from
the `agent-extensions.json` sidecar beside `Package.swift`; the pack and each
skill declare the package's `pkg:swift` purl as an identity-only companion
package.