akm docs

Adapters

A BundleAdapter (src/core/adapter/bundle-adapter.ts) is the code that decides what a bundle's files are, how they're indexed, how akm lint validates them, and where a new item would be placed. akm ships 11 built-in adapters — one per format in Supported Formats. This page is the write-path and internals reference; that page is the compatibility table.

For read-only native tool bundles, recognition is runtime translation, not conversion: the adapter projects native files into AKM's index/runtime shapes while the source file remains authoritative. AKM does not synchronize native formats, maintain translated canonical copies, or write agent/command assets back through the Claude/OpenCode adapters. Execution of agent and command assets is described in Architecture: Connections and Harnesses.

Stability note. The adapter set, bundle-recognition rules, and the bundles config shape are still evolving — see STABILITY.md.


Probe order

Each bundle root is owned by exactly one adapter, decided once at install/index time:

  1. If the bundle's config entry sets components.<id>.adapter explicitly, that adapter wins — no detection runs.
  2. Otherwise, every built-in adapter's looksLikeRoot(root) probe runs in a fixed order, most-specific markers first. The first probe that returns true claims the root.
  3. If no probe fires, the bundle falls back to the akm adapter.

The order is the array order of BUILTIN_ADAPTERS (src/core/adapter/adapters/index.ts), pinned by tests/core/adapter/registry.test.ts:

website-snapshot   -- root manifest.json {url, fetchedAt}
agent-skills       -- a <name>/SKILL.md package at the bundle root
claude             -- root CLAUDE.md + commands/|agents/|skills/
opencode           -- opencode.json(c), or root AGENTS.md + a tool dir
dotenv             -- every top-level dir is env/ and/or secrets/
akm-workflow       -- a top-level .md with explicit type: workflow
akm-task           -- a top-level task source .yml (v4 or v5, or a v2/v3 file awaiting migration)
llm-wiki           -- root schema.md + pages/
akm                -- .stash marker, or 2+ native subdirs, or fallback
okf                -- root index.md, or any .md with frontmatter type
generic-files      -- never auto-selected; explicit config only
code-project       -- never auto-selected; explicit config only

The rationale for the ordering:


BundleAdapter interface contract

Transcribed from src/core/adapter/bundle-adapter.ts:

interface BundleAdapter {
  readonly id: string;
  readonly version: string;              // feeds incrementality + fingerprints
  readonly extensions: readonly string[]; // longest-match stripping + collision priority

  // REQUIRED — single-file recognition primitive.
  recognize(c: BundleComponent, file: FileContext): IndexDocument | null;

  // REQUIRED — native validation (change-transaction pre-commit + lint --fix).
  // Adapters do not write and do not read the live filesystem: ctx serves
  // a run snapshot with pending changes overlaid, plus a read-only
  // resolveRef for link/xref existence.
  validate(c: BundleComponent, changes: FileChange[], ctx: ValidateContext): Promise<Diagnostic[]>;

  // OPTIONAL — runtime translation for executable agent/command assets: returns
  // the frontmatter-free command or persona source the execution boundary uses.
  renderExecutionSource?(c: BundleComponent, file: FileContext): AdapterRenderedExecutionSource | null;

  // OPTIONAL — the CLOSED-FORM set of existing-file placements/read aliases
  // that could own `conceptId`, used for first-owner arbitration without
  // reading authored bytes or walking the bundle.
  readCandidates?(c: BundleComponent, conceptId: string): AdapterReadCandidate[]; // { path, conceptId }

  // OPTIONAL — discovery.
  directoryList?(c: BundleComponent): string[];               // owned dirs; feeds git exact-path staging
  looksLikeRoot?(root: string): boolean;                      // install-time probe
}

recognize and validate are required on every adapter; renderExecutionSource, readCandidates, directoryList, and looksLikeRoot are optional capability methods. The core walk drives recognize() once per file; incrementality comes from the indexer's per-directory fingerprints.

readCandidates is intentionally distinct from extensions: extensions are non-exhaustive walk hints. Read candidates preserve canonical directory manifests (for example skills/<name>/SKILL.md) so lookup, index-backed show, and workflow runtime share one physical-owner decision. Each candidate carries its canonical concept identity, so a byte-denying ownership probe never has to infer identity from the query. Path-derived recognition (toCanonicalName/toAssetPath, src/core/asset/asset-placement.ts) is a deterministic function of a file's path, so its inverse — every physical spelling that could own one conceptId — is computable in closed form. A ref is the file's path relative to the bundle root minus the type's own suffix (refForFile), wherever in the bundle the file sits; filesForRef inverts it over every placement spec, including type-specific dualities (for example env's .env/<name>.env spellings for the "default" alias). A ref names no type, so every spec contributes its spelling and the adapter's recognition decides which file owns the ref. readCandidates enumerates the complete closed-form set directly from the conceptId; no bundle walk is needed, so no scan bound applies. The shared authority (src/indexer/lookup/adapter-concept-owner.ts) still probes every candidate with a byte-denying FileContext before trusting it, so an adapter returning a candidate the file does not actually own is harmless — it is simply filtered out.

The core walk — the live indexer's per-dir walk, drained by drainDirDocuments — is one implementation (symlink handling, skipped directories, git awareness); adapters do not reimplement it.

Cross-component ref existence is a core base check, not an adapter concern.


Placement

Adapters do not place new items. AKM-native writes resolve through AKM's own flat type→directory placement table (src/core/asset/asset-placement.ts's PLACEMENT_SPECS), which is correct for akm-layout bundles — the only bundles the write commands touch in practice. A per-adapter placeNew() existed through 0.9 but nothing called it, and it was removed in 0.10. Supporting writable bundles in another layout would need it back: see #1163.


Write allowlists

Which bundles AKM-native write commands may touch is decided by a small allowlist check, assertAkmAssetWrite (src/core/write-source.ts), run before any write command touches the filesystem. It compares the target bundle's detected (or configured) adapter id against an allowlist and throws a UsageError on a miss.

The default allowlist is ["akm"]. Two command families widen it explicitly:

Command Allowlist adds
akm env create / env remove / secret set / secret remove dotenv
akm workflow create akm-workflow

Every other adapter (agent-skills, claude, opencode, akm-task, generic-files, and so on) is rejected by every AKM-native write command. akm import --type task in particular uses the default allowlist (akm only), so a standalone akm-task bundle is read-only through AKM-native write commands.

Reading, searching, and akm lint are unaffected by this allowlist — only creating, editing, or deleting through AKM's own commands is restricted. "Read-only" in Supported Formats means this write-command restriction, not a filesystem permission.

AKM retrieves and validates every supported format, but its own write commands mutate only the targets on the allowlist; being able to read a format does not add it.


Task adapter

The native and standalone akm-task paths delegate to the authoritative task source parser, parseTaskSource, which accepts version: 4 (task source v4) and version: 5-beta.1 (the Experimental task source v5). A task source v4 document declares exactly one executable selector (uses or run), but its scheduling is optional — a document with no schedule: is valid and runnable manually. A version: 3 or version: 2 document is not read: it raises TASK_SCHEMA_VERSION_UNSUPPORTED, naming akm migrate apply, which converts it. The akm-task probe still recognizes a root of v2/v3 task files so the migrator can find them. Targets are akm/command and canonical commands/, workflows/, and scripts/ refs; the github-action uses: variant, agent refs, and task refs are refused. .yaml is a collection hint only: recognition gates on .yml, so a .yaml near miss is diagnosed (invalid-task-yaml) but never indexed or scheduled. See Tasks for the public source contract and the migration path.


Implementation caveats

A few adapter-specific behaviors are easy to assume differently from how they actually work:


See also