UNPKG

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

49 lines (48 loc) • 2.03 kB
// 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, parentDirHintMatcher, smartMdMatcher } from "../../indexer/walk/matchers.js"; /** * The four builtin matchers, in registration order. The array index IS the * registration index `runMatchers` uses for tie-breaking. (The `wiki` matcher * was removed in chunk 4 — the wiki asset-type is retired; LLM Wiki content is * served by the first-class `llm-wiki` adapter, not the akm adapter. The old * YAML workflow-program matcher is also gone: peer Markdown and GitHub-shaped * `.yml` workflow sources are both path-owned by residence under `workflows/` * (with Markdown frontmatter as an additional signal), while source IR owns * their distinct parse/compile semantics.) */ const AKM_MATCHERS = [ extensionMatcher, directoryMatcher, parentDirHintMatcher, smartMdMatcher, ]; function winningMatch(hits) { if (hits.length === 0) return null; hits.sort((a, b) => { const specDiff = b.result.specificity - a.result.specificity; if (specDiff !== 0) return specDiff; return b.index - a.index; }); return hits[0].result; } /** * Synchronous reproduction of `file-context.ts#runMatchers`'s arbitration * (`:242-265`), minus its `ensureBuiltinsRegistered()` dynamic import. Runs * every builtin matcher in registration order, collects the non-null * `MatchResult`s, and returns the highest-specificity one (ties broken by the * later-registered matcher — higher index — winning). Returns null when no * matcher claims the file. */ export function recognizeMatch(file) { const hits = []; for (let i = 0; i < AKM_MATCHERS.length; i++) { const result = AKM_MATCHERS[i](file); if (result !== null) hits.push({ result, index: i }); } return winningMatch(hits); }