|
| 1 | +<p align="center"> |
| 2 | + <img src="https://raw.githubusercontent.com/mcp-tool-shop-org/brand/main/logos/ai-loadout/readme.png" width="400" alt="ai-loadout"> |
| 3 | +</p> |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <a href="https://github.com/mcp-tool-shop-org/ai-loadout/actions/workflows/ci.yml"><img src="https://github.com/mcp-tool-shop-org/ai-loadout/actions/workflows/ci.yml/badge.svg" alt="CI"></a> |
| 7 | + <a href="https://www.npmjs.com/package/@mcptoolshop/ai-loadout"><img src="https://img.shields.io/npm/v/@mcptoolshop/ai-loadout" alt="npm"></a> |
| 8 | + <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License"></a> |
| 9 | +</p> |
| 10 | + |
| 11 | +Context-aware knowledge router for AI agents. |
| 12 | + |
| 13 | +`ai-loadout` is the dispatch table format and matching engine that lets AI agents load the right knowledge for the task at hand. Instead of dumping everything into context, you keep a tiny index and load payloads on demand. |
| 14 | + |
| 15 | +Think of it like a game loadout — you equip the agent with exactly the knowledge it needs before each mission. |
| 16 | + |
| 17 | +## Install |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install @mcptoolshop/ai-loadout |
| 21 | +``` |
| 22 | + |
| 23 | +## Core Concepts |
| 24 | + |
| 25 | +### The Dispatch Table |
| 26 | + |
| 27 | +A `LoadoutIndex` is a structured index of knowledge payloads: |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "version": "1.0.0", |
| 32 | + "generated": "2026-03-06T12:00:00Z", |
| 33 | + "entries": [ |
| 34 | + { |
| 35 | + "id": "github-actions", |
| 36 | + "path": ".rules/github-actions.md", |
| 37 | + "keywords": ["ci", "workflow", "runner"], |
| 38 | + "patterns": ["ci_pipeline"], |
| 39 | + "priority": "domain", |
| 40 | + "summary": "CI triggers, path gating, runner cost control", |
| 41 | + "triggers": { "task": true, "plan": true, "edit": false }, |
| 42 | + "tokens_est": 680, |
| 43 | + "lines": 56 |
| 44 | + } |
| 45 | + ], |
| 46 | + "budget": { |
| 47 | + "always_loaded_est": 320, |
| 48 | + "on_demand_total_est": 8100, |
| 49 | + "avg_task_load_est": 520, |
| 50 | + "avg_task_load_observed": null |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### Priority Tiers |
| 56 | + |
| 57 | +| Tier | Behavior | Example | |
| 58 | +|------|----------|---------| |
| 59 | +| `core` | Always loaded | "never skip tests to make CI green" | |
| 60 | +| `domain` | Loaded when task keywords match | CI rules when editing workflows | |
| 61 | +| `manual` | Never auto-loaded, explicit lookup only | Obscure platform gotchas | |
| 62 | + |
| 63 | +### Payload Frontmatter |
| 64 | + |
| 65 | +Each payload file carries its own routing metadata: |
| 66 | + |
| 67 | +```markdown |
| 68 | +--- |
| 69 | +id: github-actions |
| 70 | +keywords: [ci, workflow, runner, dependabot] |
| 71 | +patterns: [ci_pipeline] |
| 72 | +priority: domain |
| 73 | +triggers: |
| 74 | + task: true |
| 75 | + plan: true |
| 76 | + edit: false |
| 77 | +--- |
| 78 | + |
| 79 | +# GitHub Actions Rules |
| 80 | +CI minutes are finite... |
| 81 | +``` |
| 82 | + |
| 83 | +Frontmatter is the source of truth. The index is derived from it. |
| 84 | + |
| 85 | +## API |
| 86 | + |
| 87 | +### `matchLoadout(task, index)` |
| 88 | + |
| 89 | +Match a task description against a loadout index. Returns entries that should be loaded, ranked by match strength. |
| 90 | + |
| 91 | +```typescript |
| 92 | +import { matchLoadout } from "@mcptoolshop/ai-loadout"; |
| 93 | + |
| 94 | +const results = matchLoadout("fix the CI workflow", index); |
| 95 | +// [{ entry: { id: "github-actions", ... }, score: 0.67, matchedKeywords: ["ci", "workflow"] }] |
| 96 | +``` |
| 97 | + |
| 98 | +- Core entries always included (score 1.0) |
| 99 | +- Manual entries never auto-included |
| 100 | +- Domain entries scored by keyword overlap + pattern bonus |
| 101 | +- Results sorted by score descending |
| 102 | + |
| 103 | +### `lookupEntry(id, index)` |
| 104 | + |
| 105 | +Look up a specific entry by ID. For manual entries or explicit access. |
| 106 | + |
| 107 | +```typescript |
| 108 | +import { lookupEntry } from "@mcptoolshop/ai-loadout"; |
| 109 | + |
| 110 | +const entry = lookupEntry("github-actions", index); |
| 111 | +``` |
| 112 | + |
| 113 | +### `parseFrontmatter(content)` |
| 114 | + |
| 115 | +Parse YAML-like frontmatter from a payload file. |
| 116 | + |
| 117 | +```typescript |
| 118 | +import { parseFrontmatter } from "@mcptoolshop/ai-loadout"; |
| 119 | + |
| 120 | +const { frontmatter, body } = parseFrontmatter(fileContent); |
| 121 | +if (frontmatter) { |
| 122 | + console.log(frontmatter.id, frontmatter.keywords); |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +### `serializeFrontmatter(fm)` |
| 127 | + |
| 128 | +Serialize a `Frontmatter` object back to a string. |
| 129 | + |
| 130 | +### `validateIndex(index)` |
| 131 | + |
| 132 | +Validate structural integrity of a `LoadoutIndex`. Returns an array of issues. |
| 133 | + |
| 134 | +```typescript |
| 135 | +import { validateIndex } from "@mcptoolshop/ai-loadout"; |
| 136 | + |
| 137 | +const issues = validateIndex(index); |
| 138 | +const errors = issues.filter(i => i.severity === "error"); |
| 139 | +if (errors.length > 0) { |
| 140 | + console.error("Index has errors:", errors); |
| 141 | +} |
| 142 | +``` |
| 143 | + |
| 144 | +Checks: required fields, unique IDs, kebab-case format, summary bounds, keyword presence for domain entries, valid priorities, non-negative budgets. |
| 145 | + |
| 146 | +### `estimateTokens(text)` |
| 147 | + |
| 148 | +Estimate token count from text. Uses chars/4 heuristic. |
| 149 | + |
| 150 | +```typescript |
| 151 | +import { estimateTokens } from "@mcptoolshop/ai-loadout"; |
| 152 | + |
| 153 | +const tokens = estimateTokens(fileContent); // ~250 |
| 154 | +``` |
| 155 | + |
| 156 | +## Types |
| 157 | + |
| 158 | +```typescript |
| 159 | +import type { |
| 160 | + LoadoutEntry, |
| 161 | + LoadoutIndex, |
| 162 | + Frontmatter, |
| 163 | + MatchResult, |
| 164 | + ValidationIssue, |
| 165 | + Priority, // "core" | "domain" | "manual" |
| 166 | + Triggers, // { task, plan, edit } |
| 167 | + Budget, |
| 168 | +} from "@mcptoolshop/ai-loadout"; |
| 169 | +``` |
| 170 | + |
| 171 | +## Consumers |
| 172 | + |
| 173 | +- **[@mcptoolshop/claude-rules](https://github.com/mcp-tool-shop-org/claude-rules)** — CLAUDE.md optimizer for Claude Code. Uses ai-loadout for the dispatch table and matching. |
| 174 | + |
| 175 | +## Security |
| 176 | + |
| 177 | +This package is a pure data library. It does not access the filesystem, make network requests, or collect telemetry. All I/O is the consumer's responsibility. |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +Built by [MCP Tool Shop](https://mcp-tool-shop.github.io/) |
0 commit comments