Code Aggregator for AI Interaction
聚合代码,助力 AI。 Aggregate tracked code files from your Git repository into a single, context-rich file perfect for interacting with Large Language Models (LLMs) and AI assistants.
此扩展将当前代码仓库中所有符合条件的代码文件整合成单个文件,便于提交给 AI 进行提问。它遵循 .gitignore
规则,自动过滤未被追踪及非文本文件,仅聚合文本内容,帮助你更高效地获取代码上下文信息。
This extension streamlines the process of providing code context to AI models by intelligently packaging relevant files from your current workspace's Git repository into one consolidated output file. It respects your .gitignore
settings, filters out non-textual files, and includes helpful structural information, making your AI prompts more effective and efficient.
Features ✨
- Intelligent File Selection: Uses
git ls-files
to automatically include only files tracked by Git within the current workspace.
- .gitignore Aware: Naturally respects rules defined in your
.gitignore
file.
- Untracked Files Ignored: Only committed/staged files are included, avoiding clutter from temporary or ignored files.
- Text-Only Aggregation: Automatically attempts to filter out common binary file types (images, archives, executables, etc.) and files containing null characters, focusing purely on textual content.
- Clear File Structure Overview: Prepends a list of all included file paths at the beginning of the output, giving the AI (and you!) an immediate overview of the project structure.
- Distinct File Markers: Each file's content is wrapped with clear
<<<<<< START FILE: path/to/file >>>>>>
and <<<<<< END FILE: path/to/file >>>>>>
markers for easy parsing.
- Highly Configurable: Customize the behavior through VS Code settings:
- Set a maximum character limit for the output.
- Define additional folders, files, or extensions to exclude.
- Simple Command: Activate with a single command from the Command Palette.
Why Use Code Aggregator? 🤔
When interacting with AI for coding assistance, debugging, or analysis, providing sufficient context is key. Manually copying and pasting multiple files is tedious and error-prone. Code Aggregator helps by:
- ✅ Saving Time: Quickly gather all relevant code with one command.
- ✅ Improving AI Understanding: Provides a structured overview and clearly separated file contents.
- ✅ Reducing Errors: Avoids accidental inclusion of unwanted files or missing crucial ones.
- ✅ Optimizing Prompts: Helps manage context window size by filtering non-essential files and allowing character limits.
Getting Started 🚀
- Install: Install the "Code Aggregator" extension from the VS Code Marketplace.
- Open Project: Open a folder or workspace that is a Git repository.
- Run Command:
- Press
Ctrl+Shift+P
(or Cmd+Shift+P
on macOS) to open the Command Palette.
- Type
Code Aggregator
and select the command: Code Aggregator: 为 AI 打包仓库代码
.
- View Output: A new untitled file will open containing the aggregated code, ready to be copied and pasted into your AI prompt.
Configuration ⚙️
You can customize Code Aggregator's behavior via VS Code User or Workspace Settings (File > Preferences > Settings or Ctrl+,
, then search for "Code Aggregator").
Setting |
Description |
Type |
Default |
Example |
code-aggregator.maxCharacterLimit |
Maximum character limit for the aggregated content. Stops adding files if the limit would be exceeded. -1 means no limit. |
number |
-1 |
150000 |
code-aggregator.excludeFolders |
Array of folder paths (relative to workspace root, use / ) to exclude. All files within these folders will be ignored. |
array |
[] |
["dist", "build", "node_modules/.cache", "docs/internal"] |
code-aggregator.excludeFiles |
Array of specific file paths (relative to root, use / ) or filenames to exclude. |
array |
[] |
[".env.local", "config/secrets.json", "legacy_util.js"] |
code-aggregator.excludeExtensions |
Array of additional file extensions (including the leading . ) to exclude. These are added to the built-in list of binary extensions. |
array |
[] |
[".log", ".tmp", ".map", ".bak"] |
Example settings.json
:
{
"code-aggregator.maxCharacterLimit": 200000,
"code-aggregator.excludeFolders": [
"dist",
"coverage",
"vendor"
],
"code-aggregator.excludeFiles": [
".env",
"local_settings.py"
],
"code-aggregator.excludeExtensions": [
".log",
".swp"
]
}
Note: Paths in excludeFolders
and excludeFiles
should use forward slashes (/
) as path separators, even on Windows, for consistency.
Project Structure (Included Files):
====================================
src/extension.ts
src/config.ts
package.json
.gitignore
====================================
<<<<<< START FILE: src/extension.ts >>>>>>
import * as vscode from 'vscode';
// ... content of extension.ts ...
<<<<<< END FILE: src/extension.ts >>>>>>
<<<<<< START FILE: src/config.ts >>>>>>
export const DEFAULT_MAX_CHARS = -1;
// ... content of config.ts ...
<<<<<< END FILE: src/config.ts >>>>>>
<<<<<< START FILE: package.json >>>>>>
{
"name": "code-aggregator",
// ... content of package.json ...
}
<<<<<< END FILE: package.json >>>>>>
<<<<<< START FILE: .gitignore >>>>>>
node_modules
out
*.vsix
.vscode
<<<<<< END FILE: .gitignore >>>>>>
--- WARNING: Character limit (10000 chars) reached. Output may be truncated. ---
(The warning line appears only if the character limit is reached).