日本語 | 中文 | Español | Français | हिन्दी | Italiano | Português (BR)
Context-aware knowledge router for AI agents.
ai-loadout is the kernel of the Knowledge OS stack — dispatch table format, matching engine, hierarchical resolver, and agent runtime contract. Instead of dumping everything into context, you keep a tiny index and load payloads on demand.
Think of it like a game loadout — you equip the agent with exactly the knowledge it needs before each mission.
npm install -g @mcptoolshop/ai-loadout # CLI
npm install @mcptoolshop/ai-loadout # libraryA LoadoutIndex is a structured index of knowledge payloads:
{
"version": "1.0.0",
"generated": "2026-03-06T12:00:00Z",
"entries": [
{
"id": "github-actions",
"path": ".rules/github-actions.md",
"keywords": ["ci", "workflow", "runner"],
"patterns": ["ci_pipeline"],
"priority": "domain",
"summary": "CI triggers, path gating, runner cost control",
"triggers": { "task": true, "plan": true, "edit": false },
"tokens_est": 680,
"lines": 56
}
],
"budget": {
"always_loaded_est": 320,
"on_demand_total_est": 8100,
"avg_task_load_est": 520,
"avg_task_load_observed": null
}
}| Tier | Behavior | Example |
|---|---|---|
core |
Always loaded | "never skip tests to make CI green" |
domain |
Loaded when task keywords match | CI rules when editing workflows |
manual |
Never auto-loaded, explicit lookup only | Obscure platform gotchas |
Each payload file carries its own routing metadata:
---
id: github-actions
keywords: [ci, workflow, runner, dependabot]
patterns: [ci_pipeline]
priority: domain
triggers:
task: true
plan: true
edit: false
---
# GitHub Actions Rules
CI minutes are finite...Frontmatter is the source of truth. The index is derived from it.
The runtime is the canonical way agents consume a loadout. It wraps the full sequence: resolve layers → match task → decide what to load → record usage.
Plan what to load for a given task. This is the primary agent-facing function.
import { planLoad } from "@mcptoolshop/ai-loadout";
const plan = planLoad("fix the CI workflow");
// plan.preload — core entries, load immediately
// plan.onDemand — domain matches, load when needed
// plan.manual — available via explicit lookup onlyReturns a LoadPlan with:
preload/onDemand/manual— entries separated by load modeprovenance— which layer each entry came frombudget— token budget for the resolved indexpreloadTokens/onDemandTokens— token cost totalslayerNames/conflicts— layer metadata
Record that an agent loaded an entry. Enables observability (dead entries, budget drift, frequency tracking). Optional — only writes when usagePath is set in options.
Explicitly load a manual entry by ID from the resolved index.
Discovers and merges loadout indexes from a canonical layer stack:
- global —
~/.ai-loadout/index.json - org — explicit path or
$AI_LOADOUT_ORG - project —
<cwd>/.claude/loadout/index.json - session — explicit path or
$AI_LOADOUT_SESSION
Later layers win. Missing layers are normal.
import { resolveLoadout, explainEntry } from "@mcptoolshop/ai-loadout";
const { merged, layers, searched } = resolveLoadout();
// merged.entries — deduplicated entries from all layers
// merged.provenance — entryId → source layer name
const why = explainEntry("github-actions", layers);
// why.finalLayer, why.overrideChain, why.definitionsMatch a task description against a loadout index. Returns entries ranked by match strength.
import { matchLoadout } from "@mcptoolshop/ai-loadout";
const results = matchLoadout("fix the CI workflow", index);
// [{ entry, score: 0.67, matchedKeywords: ["ci", "workflow"], reason, mode }]- Core entries always included (score 1.0)
- Manual entries never auto-included
- Domain entries scored by keyword overlap + pattern bonus
- Results sorted by score descending, then by token cost ascending
Look up a specific entry by ID. For manual entries or explicit access.
Append-only JSONL usage log. Never networked, never creepy.
Find entries that have never been loaded.
Find keywords shared between entries (routing ambiguities).
Token budget breakdown with observed-vs-estimated comparison.
Deterministic merge for hierarchical loadouts. Returns a MergedIndex with provenance tracking and conflict reporting.
Parse and serialize YAML-like frontmatter from payload files.
Validate structural integrity of a LoadoutIndex. Checks: required fields, unique IDs, kebab-case format, summary bounds, keyword presence for domain entries, valid priorities, non-negative budgets.
Estimate token count from text. Uses chars/4 heuristic.
ai-loadout resolve Resolve layered loadouts
ai-loadout explain <entry-id> Explain why an entry resolved to its current state
ai-loadout validate <index> Validate index structure
ai-loadout usage <jsonl> Usage summary from event log
ai-loadout dead <index> <jsonl> Find entries never loaded
ai-loadout overlaps <index> Find keyword routing ambiguities
ai-loadout budget <index> [jsonl] Token budget breakdown
All commands support --json for scripting. Resolver commands accept --project, --global, --org, --session.
import type {
LoadoutEntry,
LoadoutIndex,
Frontmatter,
MatchResult,
ValidationIssue,
Priority, // "core" | "domain" | "manual"
Triggers, // { task, plan, edit }
LoadMode, // "eager" | "lazy" | "manual"
Budget,
UsageEvent,
MergeConflict,
MergedIndex,
LoadPlan, // returned by planLoad()
ResolvedLoadout, // returned by resolveLoadout()
EntryExplanation, // returned by explainEntry()
IssueSeverity, // "error" | "warning"
RuntimeOptions, // options for planLoad / recordLoad / manualLookup
ResolveOptions, // options for resolveLoadout / discoverLayers
UsageSummary, // returned by summarizeUsage()
DeadEntry, // returned by findDeadEntries()
KeywordOverlap, // returned by findKeywordOverlaps()
BudgetBreakdown, // returned by analyzeBudget()
DiscoveredLayer, // a layer found and loaded by the resolver
SearchedLayer, // a layer search location and its result
EntryDefinition, // one layer's version of a specific entry
} from "@mcptoolshop/ai-loadout";- @mcptoolshop/claude-rules — CLAUDE.md optimizer for Claude Code. Uses ai-loadout for the dispatch table and matching.
- @mcptoolshop/claude-memories — MEMORY.md optimizer for Claude Code. Generates dispatch tables from memory topic files.
The core matching, merging, and validation modules are pure functions with no side effects. The usage module (recordUsage / readUsage) performs local filesystem I/O to an append-only JSONL log. The resolver reads index files from canonical layer paths. No network requests, no telemetry, no native dependencies.
| Threat | Mitigation |
|---|---|
| Malformed frontmatter input | parseFrontmatter() returns null on invalid input — no exceptions, no eval |
| Prototype pollution | Hand-rolled parser uses plain object literals, no recursive merge of untrusted input |
| Index with bad data | validateIndex() catches structural issues before they propagate |
| Regex DoS | No user-supplied regex — patterns are matched as plain string lookups |
See SECURITY.md for the full security policy.
Built by MCP Tool Shop
