Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

Commit 0c17996

Browse files
mcp-tool-shopclaude
andcommitted
Initial release: context-aware knowledge router for AI agents
Dispatch table format, frontmatter spec, keyword matcher, token estimator, and index validator. The reusable routing layer that powers claude-rules and future agent knowledge systems. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2a906ea commit 0c17996

17 files changed

Lines changed: 1256 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "src/**"
8+
- "package.json"
9+
- "tsconfig.json"
10+
- ".github/workflows/**"
11+
pull_request:
12+
paths:
13+
- "src/**"
14+
- "package.json"
15+
- "tsconfig.json"
16+
- ".github/workflows/**"
17+
workflow_dispatch:
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
build-and-test:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
node-version: [20, 22]
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
- run: npm ci
35+
- run: npm run build
36+
- run: npm test
37+
- run: npm audit --audit-level=moderate
38+
- run: npm pack --dry-run

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
*.tsbuildinfo

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## 1.0.0 — 2026-03-06
4+
5+
Initial release.
6+
7+
- `LoadoutIndex` schema — dispatch table for agent knowledge
8+
- `parseFrontmatter()` / `serializeFrontmatter()` — payload file metadata
9+
- `matchLoadout()` — deterministic keyword + pattern matcher
10+
- `lookupEntry()` — explicit entry lookup by ID
11+
- `validateIndex()` — structural linter for index integrity
12+
- `estimateTokens()` — chars/4 heuristic for budget dashboards
13+
- Three priority tiers: core / domain / manual
14+
- Trigger phases: task / plan / edit
15+
- Zero production dependencies

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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/)

package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@mcptoolshop/ai-loadout",
3+
"version": "1.0.0",
4+
"description": "Context-aware knowledge router for AI agents. Dispatch table, frontmatter spec, keyword matcher, token estimator.",
5+
"type": "module",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"types": "./dist/index.d.ts",
11+
"import": "./dist/index.js"
12+
}
13+
},
14+
"scripts": {
15+
"build": "tsc",
16+
"verify": "tsc --noEmit && node --test dist/tests/*.test.js",
17+
"test": "node --test dist/tests/*.test.js",
18+
"prepublishOnly": "npm run build"
19+
},
20+
"files": [
21+
"dist",
22+
"README.md",
23+
"CHANGELOG.md",
24+
"LICENSE"
25+
],
26+
"keywords": [
27+
"ai",
28+
"agent",
29+
"loadout",
30+
"knowledge",
31+
"routing",
32+
"dispatch",
33+
"context",
34+
"frontmatter",
35+
"mcp"
36+
],
37+
"author": "mcp-tool-shop",
38+
"license": "MIT",
39+
"engines": {
40+
"node": ">=20"
41+
},
42+
"devDependencies": {
43+
"@types/node": "^22.0.0",
44+
"typescript": "^5.7.0"
45+
}
46+
}

0 commit comments

Comments
 (0)