Skip to content

Commit 19e736b

Browse files
feat: JSONC config support, stateless revert impl, and .gitignore integration
1 parent bb7d383 commit 19e736b

11 files changed

Lines changed: 1128 additions & 268 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ build/
1010

1111
# Virtual environments
1212
.venv
13-
14-
15-
buffer.md

README.md

Lines changed: 193 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Annotator
1+
# Annotator CLI
22

33
**Annotator** is a simple CLI utility that prepends relative file paths as comments to your project files as the first line.
44
It’s designed to make AI debugging easier by automatically marking file paths for better context and easier copy-pasting.
@@ -7,80 +7,224 @@ It’s designed to make AI debugging easier by automatically marking file paths
77

88
## ✨ Features
99

10-
- 🚀 **Automatically annotates** files with their relative paths.
11-
- 🛠️ **Supports many programming languages and file types** out of the box.
12-
- ⚙️ **Fully customizable** via a `.annotator.json` configuration file.
13-
- 🚫 **Exclude** specific directories, files, or extensions.
14-
-**Lightweight and fast** — no external dependencies.
10+
- 🚀 **Automatically annotates** files with their relative paths
11+
- 🔄 **Reversible** — clean annotations with `--revert`
12+
- 🎯 **Template system** — framework-specific presets (Next.js, Spring Boot, Python, React, Prisma)
13+
- ⚙️ **Fully customizable** via `.annotator.jsonc` configuration
14+
- 🚫 **Smart filtering** — respects `.gitignore`, excludes binaries, and skips nested paths
15+
- 🔍 **Stateless revert** — removes annotations using unique signature (`~annotator~`)
16+
-**Lightweight and fast** — minimal dependencies
1517

1618
---
1719

18-
## 📝 Example `.annotator.json`
20+
## 📦 Installation
1921

20-
```json
22+
### Via [pipx](https://pipx.pypa.io/) (recommended):
23+
24+
```sh
25+
pipx install annotator-cli
26+
```
27+
28+
### Via pip:
29+
30+
```sh
31+
pip install annotator-cli
32+
```
33+
34+
---
35+
36+
## 🚀 Quick Start
37+
38+
### 1. Initialize configuration
39+
40+
```sh
41+
cd /path/to/your/project
42+
annotator --init
43+
```
44+
45+
This creates `.annotator.jsonc` with sensible defaults and helpful comments.
46+
47+
### 2. Annotate your project
48+
49+
```sh
50+
annotator
51+
```
52+
53+
### 3. Revert annotations (if needed)
54+
55+
```sh
56+
annotator --revert
57+
```
58+
59+
---
60+
61+
## 📝 Configuration
62+
63+
Annotator uses a layered configuration system:
64+
65+
**Priority Chain:**
66+
`.gitignore``.annotator.jsonc``templates` (cumulative)
67+
68+
### Example `.annotator.jsonc`
69+
70+
```jsonc
2171
{
22-
"comment_styles": {
23-
".md": "<!--",
24-
"Dockerfile": "#"
72+
// List of templates to apply (keeping default is recommended)
73+
// pick additional: nextjs, react, springboot, python3, prisma ...
74+
"templates": ["default", "nextjs"],
75+
76+
// Behavior settings
77+
"settings": {
78+
"max_recursive_depth": 10, // How deep to recurse into folders
79+
"max_num_of_files": 1000, // Maximum files to process
80+
"max_file_size_kb": 512, // Skip files larger than this
2581
},
26-
"exclude_extensions": ["*.test.js", "*.spec.ts"],
27-
"exclude_dirs": ["test", "dist"],
28-
"exclude_files": [".env"]
82+
83+
// Override comment styles for specific extensions
84+
// Example: ".kt": "//", ".scala": "//"
85+
"comment_styles": {},
86+
87+
// Additional file extensions to exclude
88+
"exclude_extensions": [".log", ".cache"],
89+
90+
// Additional directories to exclude (supports nested paths)
91+
// Example: ["temp", "src/generated/proto"]
92+
"exclude_dirs": ["node_modules", ".venv", "__pycache__"],
93+
94+
// Additional specific file names to exclude
95+
"exclude_files": [".env", ".annotator.jsonc"],
2996
}
3097
```
3198

3299
<details>
33-
<summary><strong>Configuration Notes</strong></summary>
100+
<summary><strong>📋 Configuration Details</strong></summary>
101+
102+
### Templates
103+
104+
Annotator includes built-in templates for common frameworks:
34105

35-
- **comment_styles**: Maps file extensions (from the first `.` to the end) or exact filenames to their comment syntax.
36-
_Example:_ `.js``//`, `.md``<!--`. You can add any extension to annotate non-default types.
106+
- **`default`** - General-purpose config with 40+ languages, common excludes
107+
- **`nextjs`** - Next.js specific exclusions (`.next`, config files, etc.)
108+
- **`react`** - React/Vite/CRA exclusions
109+
- **`springboot`** - Spring Boot/Maven/Gradle exclusions
110+
- **`python3`** - Python virtual envs, caches, Jupyter notebooks
111+
- **`prisma`** - Prisma schema and migration exclusions
112+
113+
Templates are applied cumulatively in order. See all templates at:
114+
[github.com/assignment-sets/annotator-cli/tree/main/annotator/templates](https://github.com/assignment-sets/annotator-cli)
115+
116+
### Comment Styles
117+
118+
Maps file extensions or exact filenames to comment syntax:
119+
120+
```jsonc
121+
".js": "//",
122+
".py": "#",
123+
".html": "<!--",
124+
".css": "/*"
125+
```
37126

38-
- **exclude_extensions**: Skips all files with these full extensions (from the first `.`).
39-
_Note:_ Even if an extension is mapped in `comment_styles`, files matching an excluded extension will not be annotated.
127+
### Exclusion Rules
40128

41-
- **exclude_dirs**: Skips these directories entirely.
42-
_Note:_ Any file inside an excluded directory is never annotated, even if its extension is mapped in `comment_styles`.
129+
- **`exclude_extensions`**: Skip files by extension (e.g., `[".log", ".bin"]`)
130+
- **`exclude_dirs`**: Skip directories by name or nested path (e.g., `["node_modules", "src/generated"]`)
131+
- **`exclude_files`**: Skip specific filenames (e.g., `[".env", "package-lock.json"]`)
43132

44-
- **exclude_files**: Skips specific full filenames (with extensions) entirely.
45-
_Note:_ These take precedence over both `comment_styles` and `exclude_extensions`.
133+
**Note:** `.gitignore` patterns are always respected and have highest priority.
46134

47-
- **Extension parsing**: Extensions are always taken from the first `.` to the end of the filename.
48-
_Example:_ For a file named `file.a.b.c.js`, the full extension is `.a.b.c.js`.
135+
### Extension Parsing
136+
137+
Extensions are parsed from the last `.` to the end:
138+
139+
- `file.js``.js`
140+
- `component.test.tsx``.tsx`
141+
- `archive.tar.gz``.gz`
49142

50143
</details>
51144

52145
---
53146

54-
## Installation
147+
## 🎯 CLI Commands
55148

56-
### 1. Install pipx
149+
```sh
150+
# Annotate current directory
151+
annotator
57152

58-
Follow the official guide: [pipx Installation Guide](https://pipxproject.github.io/pipx/installation/)
153+
# Annotate specific path
154+
annotator /path/to/project
59155

60-
### 2. Install annotator-cli via [pipx](https://pipx.pypa.io/) (recommended):
156+
# Initialize configuration
157+
annotator --init
61158

62-
```sh
63-
pipx install annotator-cli
159+
# Remove all annotations
160+
annotator --revert
161+
162+
# Show help
163+
annotator --help
64164
```
65165

66166
---
67167

68-
## 🚀 Usage
168+
## 🔧 How It Works
69169

70-
### 1. Run the CLI
170+
1. **Loads configuration** from `.annotator.jsonc` and merges with selected templates
171+
2. **Respects `.gitignore`** patterns (highest priority)
172+
3. **Applies filters** based on extensions, directories, files, and size limits
173+
4. **Prepends comments** with relative path and unique signature:
71174

72-
```sh
73-
annotator /path/to/project
175+
```python
176+
# src/utils/helper.py ~annotator~
74177
```
75178

76-
Annotator will process and annotate all eligible files based on your configuration.
179+
5. **Skips already annotated** files (idempotent)
180+
6. **Revert support** removes only lines containing `~annotator~` signature
77181

78-
### 2. Uninstall (if needed)
182+
---
79183

80-
```sh
81-
pipx uninstall annotator-cli
184+
## 📚 Common Use Cases
185+
186+
### Next.js Project
187+
188+
```jsonc
189+
{
190+
"templates": ["default", "nextjs"],
191+
}
192+
```
193+
194+
### Python Data Science Project
195+
196+
```jsonc
197+
{
198+
"templates": ["default", "python3"],
199+
// customize more as you need for example
200+
"exclude_extensions": [".parquet"],
201+
}
82202
```
83203

204+
### Spring Boot Microservice
205+
206+
```jsonc
207+
{
208+
"templates": ["default", "springboot"],
209+
}
210+
```
211+
212+
### Full-Stack React + Prisma
213+
214+
```jsonc
215+
{
216+
"templates": ["default", "react", "prisma"],
217+
}
218+
```
219+
220+
---
221+
222+
## 🤝 Contributing
223+
224+
Want to add a template for your favorite framework? PRs welcome!
225+
226+
Repository: [github.com/assignment-sets/annotator-cli](https://github.com/assignment-sets/annotator-cli)
227+
84228
---
85229

86230
## ⚠️ Disclaimer
@@ -89,3 +233,13 @@ pipx uninstall annotator-cli
89233
> Use at your own risk — the author is not responsible for data loss, crashes, or security issues.
90234
91235
---
236+
237+
## 📄 License
238+
239+
MIT License - see [LICENSE](LICENSE) file for details.
240+
241+
---
242+
243+
## 🙏 Acknowledgments
244+
245+
Built to make AI-assisted debugging easier by providing better file context.

0 commit comments

Comments
 (0)