
Ai Context Kit
io.github.ofershap由 GitHub 账号 ofershap 发布v0.1.2更新于 Oct 24, 2026
Lint, measure, and sync AI context files across Cursor, Claude Code, Copilot.
概览
一个本地工具包,让助手加载、测量、检查、筛选并同步 Cursor、Claude Code、Copilot 等工具的 AI 上下文规则文件。
- 可以做什么
- 加载并自动识别 Cursor、Claude Code、AGENTS.md、Copilot、Windsurf 和 Cline 等格式的上下文规则文件,解析 frontmatter 并估算每个文件的 token 数、预算检查和占比。检查规则中的冲突、重复、超大文件、目录列表和含糊指令,并给出 0-100 分。按任务在 token 预算内只挑选相关规则,优先 alwaysApply,其次匹配任务词和标签。将单一规则来源同步到其他目标文件,支持试运行预览。按指定格式生成初始规则模板。
- 适用场景
- 适用于项目中积累多个重叠或互相矛盾的上下文文件时,想了解其 token 成本、找出冲突和重复,或只注入与当前任务相关的规则。也适合在 CI 流程中让规则错误导致构建失败。
- 运行要求
- 以本地 stdio 进程运行;需安装 npm 包 ai-context-kit,通过 npx 调用或作为库导入。未声明认证、环境变量或请求头。作用于包含受支持上下文文件的项目目录。
安装
在 SourceWeft 中
- 打开 控制台中的 Ai Context Kit,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
ai-context-kit
How do you measure the token cost of your context?
You spent hours writing the perfect .md context file, just to find out that your agent got worse.
That's not a bug. That's what happens when nobody measures the cost of context.
[Try It Now] [Install] [See Example Output] [Vote on Next Features]
[GitHub stars] [npm version] [npm downloads] [CI] [TypeScript] [License: MIT] [PRs Welcome]
You write a CLAUDE.md. Then someone adds .cursor/rules/. Then a teammate drops in an AGENTS.md. Then someone copies in a .cursorrules file from a blog post. Nobody removes the old ones.
Six months later your project has four context files that overlap, contradict each other, and dump 8,000 tokens of directory listings and "follow best practices" into every conversation. Your agent follows all of it. It gets slower. It gets confused. You blame the model.
An ETH Zurich study (February 2026) measured what actually happens when you give agents context files:
- Auto-generated context files reduced task success compared to providing nothing
- Human-written ones only improved accuracy by 4%
- Inference costs jumped 20%+ from wasted tokens
- Performance dropped on some models because agents got too obedient - following unnecessary instructions instead of solving the actual problem
I kept hitting this in my own projects, so I built ai-context-kit - a toolkit to treat context like a budget. Measure it, trim it, inject only what the current task needs.
Quick Start
Run the CLI on any project to see what you're actually injecting:
Then lint it:
That's the difference between guessing and knowing.
What's Different
What This Answers
- How much context am I injecting? Token count per file, percentage breakdown, budget check
- Are my rules fighting each other? Conflict detection across all files and formats
- What's wasting tokens? Directory listings, duplicate content, vague advice
- Which rules matter for this task? Task-relevant selection with token budget
How It Works
ai-context-kit reads every context file format in the ecosystem, parses frontmatter, estimates token cost, and gives you tools to analyze and manage them.
API
loadRules(rootDir?)
Returns RuleFile[] with parsed frontmatter, body, format, path, and token count.
measure(rules, budget?)
lint(rules)
What the linter catches:
select(rules, options)
The core insight from the research: don't inject everything. Pick what matters.
Scoring: alwaysApply: true in frontmatter gets highest priority. Then task words matched against file paths and content. Then tag matches. Budget is respected - highest-scored rules are included first until the budget runs out.
sync(options)
Write rules once, sync everywhere.
Supports dryRun: true to preview changes without writing.
init(options?)
CLI
All commands support --path <dir> to point at a different project root. lint exits with code 1 on errors (warnings pass).
Use with Vercel AI SDK / LangChain / Custom Agents
This isn't just for Cursor. If you're building agents with Vercel AI SDK, LangChain, or your own framework, ai-context-kit solves the same problem: how much context are you stuffing into the system prompt, and is it helping or hurting?
Any framework that takes a system prompt string. Any rules stored as markdown files.
Supported Formats
ai-context-kit detects the format from the file path. No configuration needed.
Why not just write better rules?
The ETH Zurich study tested both human-written and LLM-generated context files. Human-written ones were better, but only by 4%. The real problem isn't quality - it's volume. More context means more tokens consumed by instructions the agent doesn't need for the current task. The winning strategy is fewer, task-relevant rules, not better prose.
How accurate is the token estimation?
ai-context-kit uses a 4-character-per-token approximation. This is intentionally simple and fast. It's accurate enough for budgeting and comparison (GPT-4 averages ~4 chars/token for English text). If you need exact counts, pipe the output through tiktoken or your model's tokenizer.
Does this work in CI?
Yes. npx ai-context-kit lint returns exit code 1 on errors, 0 on pass. Add it to your CI pipeline the same way you'd add eslint. The --json flag gives machine-readable output for custom reporting.
Tech Stack
Contributing
PRs welcome. Whether it's a new lint rule, a format detector, or a bug fix - check out the contributing guide.
Author
README built with README Builder
License
Star this repo · Fork it · Report a bug · Join the discussion
来源:README.md,提交 8b1d7a5
工具
0版本历史
1- v0.1.2最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
