Generate contextual information from a codebase to send to an LLM.
--files=<pattern> File pattern to include (e.g., "src/*.js")
--exclude=<pattern> File pattern to exclude (e.g., "node_modules/**")
--max-size=<size> Maximum context size in KB/MB (e.g., "500KB")
--include-deps Include dependent files based on imports/requires
--depth=<num> Dependency traversal depth (default: 1)
--include-git Include git information (recent commits, authors)
--git-depth=<num> Number of recent commits to include (default: 3)
--format=<format> Output format (md, json, text) (default: md)
--summary Include short summary of each file
--show-file-sizes Include file sizes in output
--truncate-large=<size> Truncate files larger than specified size (e.g., "50KB")
./context --files="src/components/*.js" --exclude="*.test.js" --max-size=300KB --include-deps --format=md > context.txt
Extract code blocks from markdown and apply changes to the filesystem.
--dry-run Preview changes without applying them
--create-missing Create files that don't exist
--backup Create backup files before applying changes
--backup-dir=<dir> Directory for backups (default: ./.backups)
--file-marker=<regex> Regex to identify target files from markdown (default: "```[a-z]+ (.+)")
--skip-unchanged Skip files with no changes
--verbose Show detailed output about changes
--confirm Prompt for confirmation before applying each change
--only-files=<pattern> Only apply changes to files matching pattern
--ignore-files=<pattern> Ignore changes for files matching pattern
cat llm_response.md | ./apply-md --dry-run --verbose
Generate git-related context specifically to help LLMs generate meaningful commit messages.
--diff Show uncommitted changes (default: true)
--staged Show only staged changes
--unstaged Show only unstaged changes
--recent-commits=<num> Show most recent N commits for context (default: 3)
--files=<pattern> Include only files matching pattern
--exclude=<pattern> Exclude files matching pattern
--format=<format> Output format (md, json, text) (default: md)
--prompt Include commit message generation prompt
--conventional Add conventional commit format guidance
--project-context Include project name and description for context
--branch-info Include current branch and related info
- Git diff of uncommitted/staged changes
- Information about files changed (stats)
- Recent commit messages for style reference
- Optional prompt to guide the LLM in generating a good commit message
# Generate context for LLM to create commit message
./git-context --diff --recent-commits=2 --prompt --conventional > commit_context.txt
When running ./git-context --diff --recent-commits=2 --prompt --conventional
, the output might look like:
# Git Context for Commit Message Generation
## Current Changes (Diff)
```diff
diff --git a/src/components/Button.js b/src/components/Button.js
index a1b2c3d..e4f5g6h 100644
--- a/src/components/Button.js
+++ b/src/components/Button.js
@@ -12,9 +12,12 @@ function Button({ label, onClick, disabled }) {
- const handleClick = () => {
+ const handleClick = (event) => {
if (!disabled) {
- onClick();
+ onClick(event);
+ } else {
+ event.preventDefault();
+ console.log('Button is disabled');
}
};
@@ -25,7 +28,7 @@ function Button({ label, onClick, disabled }) {
disabled={disabled}
>
- {label}
+ <span className="button-text">{label}</span>
</button>
);
}
- src/components/Button.js (modified)
- 3 lines added
- 2 lines removed
- a1b2c3d: feat: add loading state to form submission (2 days ago)
- e4f5g6h: fix: resolve button click event propagation issue (4 days ago)
Based on the changes above, please generate an appropriate git commit message.
For better commit messages, consider:
- Using conventional commit format: type(scope): description
- Types: feat, fix, docs, style, refactor, perf, test, chore
- Example: "feat(button): add disabled state handling"
- Keep the first line under 72 characters
- Use the imperative mood ("add" not "added")
- Optional: Add more details after a blank line
Your commit message should describe what was changed and why.
## Usage Scenarios
### Scenario 1: Code Refactoring and Committing
1. Generate context from a specific component:
```bash
./context --files="src/components/Button.js" --include-deps > button_context.txt
-
Send to LLM (web interface):
- Request: "Refactor this Button component to improve performance and readability"
-
Apply changes from LLM response:
# Copy LLM response to clipboard, then: pbpaste | ./apply-md --dry-run pbpaste | ./apply-md
-
Generate context for commit message:
./git-context --diff --prompt --conventional > commit_context.txt
-
Send commit context to LLM to get commit command:
- LLM responds with:
git commit -m "fix(button): improve event handling and add disabled state feedback"
- LLM responds with:
-
Execute the provided commit command.
-
Generate project context:
./context --files="src/models/*.js" --include-deps > models_context.txt
-
Request feature implementation from LLM.
-
Apply changes:
pbpaste | ./apply-md --create-missing
-
Generate git context for commit message:
./git-context --diff --files="src/models/*" > commit_context.txt
-
Get commit message from LLM and execute.
-
Get context around the bug:
./context --files="src/utils/validation.js" > bug_context.txt
-
Send to LLM with bug description, receive fix.
-
Apply fix:
pbpaste | ./apply-md
-
Generate commit context with reference to recent commits:
./git-context --diff --recent-commits=5 > commit_context.txt
-
Get clear bug-fix commit message from LLM and execute.