akm-cli
Version:
akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur
36 lines (35 loc) • 2.05 kB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
import { directoryMatcher, extensionMatcher, looseMarkdownMatcher, parentDirHintMatcher, smartMdMatcher, } from "./directory/matchers.js";
/**
* Every matcher in registration order (the order breaks ties: of equal specificity the later one wins), the Markdown
* matcher last. It has a path-only form ({@link looseMarkdownMatcher}) and a content form ({@link smartMdMatcher}).
* (There is no `wiki` matcher — the wiki asset-type is retired; LLM Wiki content is served by the first-class
* `llm-wiki` adapter, not the akm adapter. There is no YAML workflow-program matcher: Markdown workflow sources are
* path-owned by residence under `workflows/`, with Markdown frontmatter as an additional signal.)
*/
function arbitrate(file, markdown) {
let winner = null;
for (const result of [extensionMatcher(file), directoryMatcher(file), parentDirHintMatcher(file), markdown(file)]) {
if (result !== null && (winner === null || result.specificity >= winner.specificity))
winner = result;
}
return winner;
}
/**
* The type a file's path gives it: the folder rules, `SKILL.md`, a script extension; any other `.md` is knowledge. No
* content is read, so this is what identity and the write gates use.
*/
export function recognizeMatchByPath(file) {
return arbitrate(file, looseMarkdownMatcher);
}
/**
* The type the index records for a file: {@link recognizeMatchByPath}, except that a loose Markdown file is typed by
* its content (`type: workflow`, `agent:`, `$ARGUMENTS`, `model:`) as the matchers did before the adapter refactor.
* Synchronous reproduction of `file-context.ts#runMatchers`'s arbitration, minus its `ensureBuiltinsRegistered()`
* dynamic import. Returns null when no matcher claims the file.
*/
export function recognizeMatch(file) {
return arbitrate(file, smartMdMatcher);
}