LLM背景
LLM开发工作流的智能上下文管理。 通过智能选择和基于规则的过滤,即时共享相关项目文件。
问题
在LLM对话中获得正确的背景是充满摩擦的:
- 手动查找和复制相关文件浪费时间
- 太多的上下文触及了令牌的极限,太少的上下文遗漏了重要的细节
- 对其他文件的AI请求需要手动获取
- 很难跟踪开发会议期间发生了什么变化
解决方案
llm上下文通过可组合规则提供专注的、特定于任务的项目上下文。
对于使用聊天界面的人:
BASH``` 1 2 3lc-select # Smart file selection lc-context # Copy formatted context to clipboard
Paste and work - AI can access additional files via MCP
**对于具有CLI访问权限的AI代理:**
BASH```
1
2lc-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精心策划的。
安装
BASH``` 1uv tool install “llm-context>=0.6.0”
## 快速开始
### 人工工作流(剪贴板)
BASH```
1
2
3
4
5
6
7# One-time setup
cd your-project
lc-init
# Daily usage
lc-select
lc-context
# Paste into your LLM chat
MCP集成(推荐)
添加到Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json):
JSONC``` 1 2 3 4 5 6 7 8{ “mcpServers”: { “llm-context”: { “command”: “uvx”, “args”: [“—from”, “llm-context”, “lc-mcp”] } } }
重新启动克劳德桌面。现在,AI可以在对话过程中访问其他文件,而无需手动复制。
### 代理工作流(CLI)
具有shell访问权限的AI代理使用llm上下文创建聚焦上下文:
BASH```
1
2
3
4
5
6
7
8# 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工具:
BASH``` 1 2 3 4 5 6# 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文件:
YAML```
1
2
3
4
5
6
7
8
9---
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)
规则组成
从简单规则构建复杂规则:
YAML``` 1 2 3 4 5 6--- 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 <name>` | 切换活动规则 |
| `lc-preview <rule>` | 验证规则选择和大小 |
| `lc-outlines` | 获取代码结构摘录 |
| `lc-missing` | 获取文件/实现(手动MCP) |
## 人工智能辅助规则创建
让人工智能帮助创建专注的、特定任务的规则。根据您的环境,有两种方法:
### 克劳德技能(互动,克劳德桌面/代码)
**运作原理**:全局技能指导您以交互方式创建规则。根据需要使用MCP工具检查您的代码库。
**设置**:
BASH```
1
2lc-init # Installs skill to ~/.claude/skills/
# Restart Claude Desktop or Claude Code
用法:
BASH``` 1 2 3 4 5# 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”
克劳德将:
1. 在上下文中使用项目概述
2. 通过以下方式检查特定文件 `lc-missing` 根据需要
3. 提出关于范围的澄清问题
4. 生成优化规则(`tmp-prm-<task>.md`)
5. 提供验证说明
**技能文档** (逐步披露):
- `Skill.md` -快速的工作流程、决策模式
- `PATTERNS.md` -常见规则模式
- `SYNTAX.md` -详细参考
- `EXAMPLES.md` -完整演练
- `TROUBLESHOOTING.md` -解决问题
### 指令规则(适用于任何地方)
**运作原理**:将全面的规则创建文档加载到上下文中,使用任何LLM。
**用法**:
BASH```
1
2
3
4
5
6
7
8
9
10
11# 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,任何环境 |
| 更新 | 自动进行版本升级 | 内置规则 |
两者都需要首先共享项目上下文。两者都产生了相同的结果。
项目定制
创建基本筛选器
BASH``` 1 2 3 4 5 6 7 8 9 10cat > .llm-context/rules/flt-repo-base.md << ‘EOF’
description: “Repository-specific exclusions” compose: filters: [lc/flt-base] gitignores: full-files: [“.md”, “/tests”, “/node_modules”] excerpted-files: [“.md”, “/tests”]
EOF
### 创建开发规则
BASH```
1
2
3
4
5
6
7
8
9
10
11cat > .llm-context/rules/prm-code.md << 'EOF'
---
description: "Main development rule"
instructions: [lc/ins-developer, lc/sty-python]
compose:
filters: [flt-repo-base]
excerpters: [lc/exc-base]
---
Additional project-specific guidelines and context.
EOF
lc-set-rule prm-code
部署模式
根据您的LLM环境选择格式:
| 模式 | 命令 | 用例 |
|---|---|---|
| 系统消息 | lc-context -p | AI工作室等。 |
| 单用户消息 | lc-context -p -m | Grok等。 |
| 单独消息 | lc-prompt + lc-context -m | 灵活放置 |
| 项目文件(包括) | lc-context | 克劳德项目等。 |
| 项目文件(可搜索) | lc-context -m | 将力融入上下文 |
看 部署模式 了解详情。
主要特点
- 智能选择:规则自动包含/排除适当的文件
- 上下文验证:生成前预览大小和选择
- 代码摘录:在减少标记的同时提取结构(15+种语言)
- MCP集成:AI无需人工干预即可访问其他文件
- 可组合规则:从可重用模式构建复杂上下文
- 人工智能辅助创作:互动技能或基于文档的方法
- 代理商友好:用于自主操作的CLI和MCP接口
常见工作流
日常发展(人类)
BASH``` 1 2 3 4lc-set-rule prm-code lc-select lc-context
Paste into chat - AI accesses more files via MCP if needed
### 专注任务(人工或代理)
BASH```
1
2
3
4
5
6
7
8# Share project context first
lc-context
# Then create focused rule:
# Via Skill: "Create a rule for [task]"
# Via Instructions: lc-set-rule lc/prm-rule-create && lc-context -nt
# Validate and use
lc-preview tmp-prm-task
lc-context tmp-prm-task
代理上下文配置(CLI)
BASH``` 1 2 3 4 5# Agent validates rule effectiveness lc-preview tmp-prm-refactor-auth
Agent generates context for sub-agent
lc-context tmp-prm-refactor-auth > /tmp/context.md
Sub-agent reads context and executes task
### 代理上下文配置(MCP)
PYTHON```
1
2
3
4
5
6# 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)
路径格式
所有路径都使用带有项目名称前缀的项目相对格式:
1
2/{project-name}/src/module/file.py
/{project-name}/tests/test_module.py
这使得多项目上下文组合没有路径冲突。
在规则中,模式是相对于项目的,没有前缀:
YAML``` 1 2 3 4also-include: full-files: - “/src/auth/” # ✓ Correct - “/myproject/src/” # ✗ Wrong - don’t include project name
## 了解更多
- **用户指南** -带示例的完整文档
- **[设计理念](https://www.cyberchitta.cc/articles/llm-ctx-why.html)** -为什么存在llm上下文
- **[真实世界的例子](https://www.cyberchitta.cc/articles/full-context-magic.html)** -有效利用完整上下文
## 许可证
Apache许可证,版本2.0。看 许可证 了解详情。