Skip to content

Commit ffa29f7

Browse files
committed
1 parent 5526287 commit ffa29f7

File tree

6 files changed

+738
-0
lines changed

6 files changed

+738
-0
lines changed

docs/apply-md.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# `apply-md` - Markdown Code Applier
2+
3+
## Overview
4+
5+
The `apply-md` tool extracts code blocks from markdown (typically LLM responses) and applies them to your filesystem.
6+
7+
## Usage
8+
9+
```bash
10+
cat llm_response.md | ./apply-md --dry-run --verbose
11+
```
12+
13+
## Arguments
14+
15+
| Argument | Description | Default |
16+
|----------|-------------|---------|
17+
| `--dry-run` | Preview changes without applying them | False |
18+
| `--create-missing` | Create files that don't exist | False |
19+
| `--backup` | Create backup files before applying changes | False |
20+
| `--backup-dir=<dir>` | Directory for backups | "./.backups" |
21+
| `--file-marker=<regex>` | Regex to identify target files from markdown | "```[a-z]+ (.+)" |
22+
| `--skip-unchanged` | Skip files with no changes | False |
23+
| `--verbose` | Show detailed output about changes | False |
24+
| `--confirm` | Prompt for confirmation before applying each change | False |
25+
| `--only-files=<pattern>` | Only apply changes to files matching pattern | None |
26+
| `--ignore-files=<pattern>` | Ignore changes for files matching pattern | None |
27+
28+
## How It Works
29+
30+
1. The tool reads markdown content from stdin
31+
2. It looks for code blocks that specify a filename (e.g., ```javascript src/utils.js)
32+
3. It extracts the code from these blocks
33+
4. It applies the code to the corresponding files in your filesystem
34+
35+
## Examples
36+
37+
### Basic Usage
38+
39+
Apply changes directly from an LLM response:
40+
41+
```bash
42+
cat llm_response.md | ./apply-md
43+
```
44+
45+
### Dry Run
46+
47+
Preview changes without applying them:
48+
49+
```bash
50+
cat llm_response.md | ./apply-md --dry-run --verbose
51+
```
52+
53+
### With Backups
54+
55+
Make backups before applying changes:
56+
57+
```bash
58+
cat llm_response.md | ./apply-md --backup
59+
```
60+
61+
### Creating New Files
62+
63+
Allow creating files that don't exist:
64+
65+
```bash
66+
cat llm_response.md | ./apply-md --create-missing
67+
```
68+
69+
### Selective Application
70+
71+
Only apply changes to specific files:
72+
73+
```bash
74+
cat llm_response.md | ./apply-md --only-files="*.js"
75+
```
76+
77+
## Expected Markdown Format
78+
79+
The script expects code blocks in this format:
80+
81+
````
82+
```javascript src/utils.js
83+
function add(a, b) {
84+
return a + b;
85+
}
86+
```
87+
````
88+
89+
The language specification is optional, but the filename is required.
90+
91+
## Tips
92+
93+
- Always use `--dry-run` first to preview changes
94+
- Consider using `--backup` for important changes
95+
- Use `--verbose` to see details about what's changing
96+
- For complex changes, use `--confirm` to review each change individually

docs/context.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# `context` - Code Context Generator
2+
3+
## Overview
4+
5+
The `context` tool extracts relevant code and context from your codebase to send to an LLM (Large Language Model).
6+
7+
## Usage
8+
9+
```bash
10+
./context --files="src/components/*.js" --exclude="*.test.js" --max-size=300KB --format=md > context.txt
11+
```
12+
13+
## Arguments
14+
15+
| Argument | Description | Default |
16+
|----------|-------------|---------|
17+
| `--files=<pattern>` | File pattern to include (e.g., "src/*.js") | Required |
18+
| `--exclude=<pattern>` | File pattern to exclude (e.g., "node_modules/**") | None |
19+
| `--max-size=<size>` | Maximum context size in KB/MB (e.g., "500KB") | "500KB" |
20+
| `--include-deps` | Include dependent files based on imports/requires | False |
21+
| `--depth=<num>` | Dependency traversal depth | 1 |
22+
| `--include-git` | Include git information (recent commits, authors) | False |
23+
| `--git-depth=<num>` | Number of recent commits to include | 3 |
24+
| `--format=<format>` | Output format (md, json, text) | "md" |
25+
| `--summary` | Include short summary of each file | False |
26+
| `--show-file-sizes` | Include file sizes in output | False |
27+
| `--truncate-large=<size>` | Truncate files larger than specified size (e.g., "50KB") | None |
28+
29+
## Examples
30+
31+
### Basic Usage
32+
33+
Extract all JS files in the src directory:
34+
35+
```bash
36+
./context --files="src/**/*.js" > code_context.md
37+
```
38+
39+
### With Dependencies
40+
41+
Include imported/required files (1 level deep):
42+
43+
```bash
44+
./context --files="src/components/Button.js" --include-deps > button_context.md
45+
```
46+
47+
### Include Git Information
48+
49+
Generate context with git history:
50+
51+
```bash
52+
./context --files="src/utils/*.js" --include-git --git-depth=5 > utils_context.md
53+
```
54+
55+
### JSON Output
56+
57+
Get context in JSON format for programmatic usage:
58+
59+
```bash
60+
./context --files="*.py" --format=json > context.json
61+
```
62+
63+
## Customization
64+
65+
The script is designed to be simple and easy to modify. You can:
66+
67+
1. Add support for more languages in the dependency resolution
68+
2. Modify the output format for your specific needs
69+
3. Add additional metadata to the context generation
70+
71+
## Tips
72+
73+
- When working with LLMs, try to keep the context focused and relevant
74+
- Use `--exclude` to filter out test files, build artifacts, etc.
75+
- The `--summary` flag can help provide high-level context about each file
76+
- If you hit token limits, use `--truncate-large` to limit file sizes

docs/git-context.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# `git-context` - Git Context Generator
2+
3+
## Overview
4+
5+
The `git-context` tool generates git-related context specifically to help LLMs create meaningful commit messages.
6+
7+
## Usage
8+
9+
```bash
10+
./git-context --diff --recent-commits=2 --prompt --conventional > commit_context.txt
11+
```
12+
13+
## Arguments
14+
15+
| Argument | Description | Default |
16+
|----------|-------------|---------|
17+
| `--diff` | Show uncommitted changes | True |
18+
| `--no-diff` | Don't show uncommitted changes | False |
19+
| `--staged` | Show only staged changes | False |
20+
| `--unstaged` | Show only unstaged changes | False |
21+
| `--recent-commits=<num>` | Show most recent N commits for context | 3 |
22+
| `--files=<pattern>` | Include only files matching pattern | None |
23+
| `--exclude=<pattern>` | Exclude files matching pattern | None |
24+
| `--format=<format>` | Output format (md, json, text) | "md" |
25+
| `--prompt` | Include commit message generation prompt | False |
26+
| `--conventional` | Add conventional commit format guidance | False |
27+
| `--project-context` | Include project name and description for context | False |
28+
| `--branch-info` | Include current branch and related info | False |
29+
30+
## Output
31+
32+
The tool outputs git context information, which typically includes:
33+
34+
1. Git diff of uncommitted/staged changes
35+
2. Information about files changed (stats)
36+
3. Recent commit messages for style reference
37+
4. Optional prompt to guide the LLM in generating a good commit message
38+
39+
## Examples
40+
41+
### Basic Usage
42+
43+
Generate context for a commit message:
44+
45+
```bash
46+
./git-context > commit_context.txt
47+
```
48+
49+
### Conventional Commits
50+
51+
Include guidance for conventional commit format:
52+
53+
```bash
54+
./git-context --prompt --conventional > commit_context.txt
55+
```
56+
57+
### With Project Context
58+
59+
Include project information for better context:
60+
61+
```bash
62+
./git-context --project-context --branch-info > commit_context.txt
63+
```
64+
65+
### Staged Changes Only
66+
67+
Only include changes that have been staged:
68+
69+
```bash
70+
./git-context --staged --prompt > commit_context.txt
71+
```
72+
73+
### JSON Output
74+
75+
Generate context in JSON format:
76+
77+
```bash
78+
./git-context --format=json > commit_context.json
79+
```
80+
81+
## Customization
82+
83+
The commit message prompt template is stored in `prompts/commit_prompt.txt` and can be customized to your project's needs.
84+
85+
If the `--conventional` flag is used, the tool will also include guidance from `prompts/conventional_commit.txt`.
86+
87+
## Workflow Integration
88+
89+
Typical workflow:
90+
91+
1. Make changes to your code
92+
2. Stage changes with `git add`
93+
3. Run `./git-context --staged --prompt > commit_context.txt`
94+
4. Send commit_context.txt to an LLM to generate a commit message
95+
5. Use the generated message with `git commit -m "generated message"`

0 commit comments

Comments
 (0)