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
bundlesconfig shape are still evolving — see STABILITY.md.
Probe order
Each bundle root is owned by exactly one adapter, decided once at install/index time:
- If the bundle's config entry sets
components.<id>.adapterexplicitly, that adapter wins — no detection runs. - Otherwise, every built-in adapter's
looksLikeRoot(root)probe runs in a fixed order, most-specific markers first. The first probe that returnstrueclaims the root. - If no probe fires, the bundle falls back to the
akmadapter.
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:
- The three loosest probes —
llm-wiki,akm, andokf— stay last. Native AKM evidence wins before OKF because AKM Markdown is an OKF superset; theakmprobe is strict enough not to claim an OKF bundle merely because it contains one familiar directory name. akm.looksLikeRootfires on any root carrying a bundle-subdir-named directory — which includes a.claude/.opencodetool dir (commands/,agents/,skills/) and a dotenv bundle (env/,secrets/). Soclaude/opencode/dotenvcome ahead ofakm; their tighter markers claim those roots first, andakmstill wins its own workspace root (which those tighter probes reject).website-snapshot,agent-skills,akm-workflow, andakm-taskcarry disjoint, specific markers that fire on none of the other roots, so they sit at the front for clarity.generic-filesis explicit-config-only — itslooksLikeRootnever fires — so it's last and can never shadow anything.
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:
agent-skillsrecognition/validation are decoupled. The per-change half ofvalidate()only inspects changes that resolve to an actualSKILL.md, so an invalid skill is still indexed asskill(with its raw, invalid name projected) and its field violations surface only for files that exist.missing-skill-mdis the exception and runs as a separate directory pass overValidateContext.list: a top-level directory that holds files but noSKILL.mdanywhere within three levels is flagged. A package's own resource dirs (pdf-processing/reference/) are part of the item, not candidate packages, and are never considered.- The base checks have one implementation.
unquoted-colon,missing-updated,stale-path,missing-refandredacted-contentarerunBaseChecks(src/commands/lint/base-linter.ts), andruleApplies(src/core/asset/lint-text.ts) decides whether a rule applies to a file (the skill and LLM Wiki exemptions, the bundle'slint.skip, an adapter's own exclusions). Theakm lintsweep and every adapter'svalidatecall them;createBaseChecker(adapters/shared.ts) is the adapter's way in. It reads refs from disk, the other bundles fromValidateContext.sourcesand the settings fromValidateContext.config(the run's own; it reads the config itself only when the context carries none), so a pending change in the context does not satisfy a ref, and it never writes. The per-type checks are one table,perTypeChecks(adapters/akm-lint.ts), keyed by akm type and read by the sweep and byvalidate; the one exception is the skill folder check, which has a directory walk for the sweep andskillDirectoryDiagnosticsforvalidate. Add a rule or an exemption there, not in an adapter. claude/opencodeshare one codec (tool-dir-shared.ts) and differ only in instruction filename and adapter/component ids. Both accept only the canonical plural tool directories.dotenvredaction is keyed on the adapter. A frontmattertype:does not change it:enventries surface only key names andsecretentries surface only the file name. A.envfile placed undersecrets/is a secret (name-only), not an env group — the directory wins over the.envsuffix.- Task adapters share one task source parser. A standalone
akm-taskbundle and task files owned by the nativeakmadapter both route throughparseTaskSource(see Task adapter). akmandokfreserveindex.md/log.mdas structural files — never indexed as concepts, never valid write targets — at any depth.llm-wikireservesschema.md,index.mdandlog.mdonly at the wiki root.okf's lenient wording is not a lenient gate.missing-typeand broken-link findings are labelledinfo:/warning:in the diagnostic text, but diagnostics carry no severity field:akm lintfunnels every finding into oneflaggedlist, and--fail-on-flaggedfails on any non-empty list.generic-filesis the only adapter with no auto-detection at all.looksLikeRootalways returnsfalse; a bundle only gets this adapter through an explicitcomponents.<id>.adapter: "generic-files"override.
See also
- Supported Formats — the compatibility table this page's internals back
- Asset Types — the
akmadapter's 14 native asset types - Concepts — the retrieval loop these adapters serve
- Architecture — sources, refs, the search pipeline, and the write-source chokepoint