LLM背景
 ](https://pypi.org/project/llm-context/) ](https://pepy.tech/project/llm-context)
LLM开发工作流的智能上下文管理。 通过智能选择和基于规则的过滤,即时共享相关项目文件。
问题
在LLM对话中获得正确的背景是充满摩擦的:
- 手动查找和复制相关文件浪费时间
- 太多的上下文触及了令牌的极限,太少的上下文遗漏了重要的细节
- 对其他文件的AI请求需要手动获取
- 很难跟踪开发会议期间发生了什么变化
解决方案
llm上下文通过可组合规则提供专注的、特定于任务的项目上下文。
对于使用聊天界面的人:
lc-select # Smart file selection
lc-context # Copy formatted context to clipboard
# Paste and work - AI can access additional files via MCP对于具有CLI访问权限的AI代理:
lc-preview tmp-prm-auth # Validate rule selects right files
lc-context tmp-prm-auth # Get focused context for sub-agent对于聊天中的AI代理(MCP工具):
lc_outlines-从当前规则生成摘录上下文lc_preview-使用前验证规则的有效性lc_missing-按需获取特定文件/实现
备注:这个项目是与几个Claude十四行诗(3.5、3.6、3.7、4.0)和Groks(3、4)合作开发的,在开发过程中使用LLM Context本身共享代码。所有代码都是由@restlessronin精心策划的。
安装
uv tool install "llm-context>=0.6.0"快速开始
人工工作流(剪贴板)
# One-time setup
cd your-project
lc-init
# Daily usage
lc-select
lc-context
# Paste into your LLM chatMCP集成(推荐)
添加到Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"llm-context": {
"command": "uvx",
"args": ["--from", "llm-context", "lc-mcp"]
}
}
}重新启动克劳德桌面。现在,AI可以在对话过程中访问其他文件,而无需手动复制。
代理工作流(CLI)
具有shell访问权限的AI代理使用llm上下文创建聚焦上下文:
# Agent explores codebase
lc-outlines
# Agent creates focused rule for specific task
# (via Skill or lc-rule-instructions)
# Agent validates rule
lc-preview tmp-prm-oauth-task
# Agent uses context for sub-task
lc-context tmp-prm-oauth-task代理工作流(MCP)
聊天环境中的AI代理使用MCP工具:
# Explore codebase structure
lc_outlines(root_path, rule_name)
# Validate rule effectiveness
lc_preview(root_path, rule_name)
# Fetch specific files/implementations
lc_missing(root_path, param_type, data, timestamp)核心概念
规则:任务特定上下文描述符
规则是描述为任务提供什么上下文的YAML+Markdown文件:
---
description: "Debug API authentication"
compose:
filters: [lc/flt-no-files]
excerpters: [lc/exc-base]
also-include:
full-files: ["/src/auth/**", "/tests/auth/**"]
---
Focus on authentication system and related tests.五个规则类别
- 提示规则(
prm-):生成项目上下文(例如。,lc/prm-developer) - 筛选规则(
flt-):控制文件包含(例如。,lc/flt-base,lc/flt-no-files) - 指令规则(
ins-):提供指导方针(例如。,lc/ins-developer) - 风格规则(
sty-):执行编码标准(例如。,lc/sty-python) - 摘录规则(
exc-):配置内容提取(例如。,lc/exc-base)
规则组成
从简单规则构建复杂规则:
---
instructions: [lc/ins-developer, lc/sty-python]
compose:
filters: [lc/flt-base, project-filters]
excerpters: [lc/exc-base]
---基本命令
| 命令 | 目的 |
|---|---|
lc-init | 初始化项目配置 |
lc-select | 根据当前规则选择文件 |
lc-context | 生成并复制上下文 |
lc-context -p | 包括提示说明 |
lc-context -m | 格式化为单独的消息 |
lc-context -nt | 无工具(手动工作流程) |
lc-set-rule | 切换活动规则 |
lc-preview | 验证规则选择和大小 |
lc-outlines | 获取代码结构摘录 |
lc-missing | 获取文件/实现(手动MCP) |
人工智能辅助规则创建
让人工智能帮助创建专注的、特定任务的规则。根据您的环境,有两种方法:
克劳德技能(互动,克劳德桌面/代码)
运作原理:全局技能指导您以交互方式创建规则。根据需要使用MCP工具检查您的代码库。
设置:
lc-init # Installs skill to ~/.claude/skills/
# Restart Claude Desktop or Claude Code用法:
# 1. Share project context
lc-context # Any rule - overview included
# 2. Paste into Claude, then ask:
# "Create a rule for refactoring authentication to JWT"
# "I need a rule to debug the payment processing"克劳德将:
- 在上下文中使用项目概述
- 通过以下方式检查特定文件
lc-missing根据需要 - 提出关于范围的澄清问题
- 生成优化规则(
tmp-prm-.md) - 提供验证说明
技能文档 (逐步披露):
Skill.md-快速的工作流程、决策模式PATTERNS.md-常见规则模式SYNTAX.md-详细参考EXAMPLES.md-完整演练TROUBLESHOOTING.md-解决问题
指令规则(适用于任何地方)
运作原理:将全面的规则创建文档加载到上下文中,使用任何LLM。
用法:
# 1. Load framework
lc-set-rule lc/prm-rule-create
lc-select
lc-context -nt
# 2. Paste into any LLM
# "I need a rule for adding OAuth integration"
# 3. LLM generates focused rule using framework
# 4. Use the new rule
lc-set-rule tmp-prm-oauth
lc-select
lc-context包括文件:
lc/ins-rule-intro-引言与概述lc/ins-rule-framework-完整的决策框架
比较
| 方面 | 技能 | 指导规则 |
|---|---|---|
| 设置 | 自动带 lc-init | 已经可用 |
| 交互 | 交互式,使用 lc-missing | 静态文档 |
| 档案检查 | 通过MCP自动 | 手动或通过AI |
| 最适合 | 克劳德桌面/代码 | 任何LLM,任何环境 |
| 更新 | 自动进行版本升级 | 内置规则 |
两者都需要首先共享项目上下文。两者都产生了相同的结果。
项目定制
创建基本筛选器
cat > .llm-context/rules/flt-repo-base.md .llm-context/rules/prm-code.md /tmp/context.md
# Sub-agent reads context and executes task代理上下文配置(MCP)
# Agent validates rule
preview = lc_preview(root_path="/path/to/project", rule_name="tmp-prm-task")
# Agent generates context
context = lc_outlines(root_path="/path/to/project")
# Agent fetches additional files as needed
files = lc_missing(root_path, "f", "['/proj/src/auth.py']", timestamp)路径格式
所有路径都使用带有项目名称前缀的项目相对格式:
/{project-name}/src/module/file.py
/{project-name}/tests/test_module.py这使得多项目上下文组合没有路径冲突。
在规则中,模式是相对于项目的,没有前缀:
also-include:
full-files:
- "/src/auth/**" # ✓ Correct
- "/myproject/src/**" # ✗ Wrong - don't include project name了解更多
许可证
Apache许可证,版本2.0。看 许可证 了解详情。
