Skip to content

Commit 7371e50

Browse files
jeremyederclaude
andauthored
docs: Add repomap workflow automation (#23)
* Add repomap workflow automation - Add scripts/update-repomap.sh for automated repomap management - Add pre-commit hook to auto-update repomap on code changes - Add CI validation to ensure repomap stays current - Update documentation (README.md, CLAUDE.md, docs/patterns/repomap.md) - Add scripts/README.md documenting all automation scripts The repomap now automatically updates when committing code changes and CI validates it's current on every push/PR. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Replace pip with uv throughout documentation - Update all package installation commands to use uv - Update CI workflow to install and use uv - Update error messages in scripts to recommend uv - Keep pip only for bootstrapping uv in CI environments Per project standards: always prefer uv over pip for package management. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 51dc7dc commit 7371e50

7 files changed

Lines changed: 470 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ jobs:
2121
test -f docs/README.md || { echo "Error: docs/README.md missing"; exit 1; }
2222
test -d docs/adr || { echo "Error: docs/adr/ missing"; exit 1; }
2323
echo "All required documentation files present"
24+
25+
repomap-validation:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: '3.11'
35+
36+
- name: Install repomap dependencies
37+
run: |
38+
pip install uv
39+
uv pip install tree-sitter tree-sitter-python tree-sitter-javascript \
40+
tree-sitter-typescript tree-sitter-go tree-sitter-bash
41+
42+
- name: Validate repomap is current
43+
run: |
44+
chmod +x scripts/update-repomap.sh
45+
./scripts/update-repomap.sh --check

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
repos:
22
- repo: local
33
hooks:
4+
- id: repomap-update
5+
name: Update repository map
6+
entry: scripts/update-repomap.sh
7+
language: system
8+
pass_filenames: false
9+
files: '\.(py|js|ts|tsx|go|sh|bash)$'
10+
description: Regenerate .repomap.txt when code structure changes
11+
412
- id: mkdocs-build
513
name: mkdocs build --strict
614
entry: .venv/bin/mkdocs build --strict

CLAUDE.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,26 @@ cat .repomap.txt
135135
- Major refactoring is completed
136136
- Before creating PRs (ensure map is current)
137137

138+
**Automated regeneration**:
139+
140+
The repository includes automation for repomap management:
141+
138142
```bash
139-
# Regenerate after changes
143+
# Manual regeneration (recommended method)
144+
./scripts/update-repomap.sh
145+
146+
# Check if repomap is current
147+
./scripts/update-repomap.sh --check
148+
149+
# Legacy manual method (still works)
140150
python repomap.py . > .repomap.txt
141151
git add .repomap.txt # Include in commits
142152
```
143153

154+
**Pre-commit hook**: The repomap is automatically regenerated when you commit changes to code files (`.py`, `.js`, `.ts`, `.tsx`, `.go`, `.sh`, `.bash`) via the pre-commit hook.
155+
156+
**CI validation**: The CI workflow validates that the repomap is current on every push/PR.
157+
144158
#### Integration with Development Workflow
145159

146160
**Include repomap in commit tracking**:
@@ -383,6 +397,7 @@ Focus on "why" rather than "what".
383397
3. **`.github/workflows/ci.yml`** (General CI)
384398
- Code example linting (if any)
385399
- Documentation build test
400+
- Repomap validation (ensures .repomap.txt is current)
386401
- Triggers: on push, PR
387402

388403
4. **`.github/workflows/deploy-docs.yml`** (Documentation Deployment)
@@ -422,9 +437,15 @@ Teams can extend with:
422437
git clone https://github.com/yourusername/reference.git
423438
cd reference
424439

440+
# Install repomap dependencies
441+
uv pip install -r requirements.txt
442+
425443
# Install doc tooling
426444
uv pip install -r requirements-dev.txt
427445

446+
# Install pre-commit hooks
447+
pre-commit install
448+
428449
# Load repomap (session start)
429450
cat .repomap.txt
430451

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ See [Quickstart](docs/README.md) for pattern overview and adoption guidance.
2525
```bash
2626
git clone https://github.com/ambient-code/reference.git
2727
cd reference
28-
./scripts/setup.sh
29-
source .venv/bin/activate
28+
29+
# Install dependencies
30+
uv pip install -r requirements.txt # Repomap dependencies
31+
uv pip install -r requirements-dev.txt # Doc tooling
32+
33+
# Install pre-commit hooks (includes repomap auto-update)
3034
pre-commit install
3135
```
3236

docs/patterns/repomap.md

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ Generate clean, token-optimized code structure maps using tree-sitter for AI-ass
88

99
## Quick Start
1010

11+
This repository includes **complete automation** for repomap management. The repomap is automatically updated via pre-commit hooks and validated in CI.
12+
1113
```bash
12-
# Install dependencies
13-
pip install -r requirements.txt
14+
# Install dependencies (includes tree-sitter packages)
15+
uv pip install -r requirements.txt
1416

15-
# Generate map of current directory
16-
python repomap.py .
17+
# Install pre-commit hooks (includes repomap auto-update)
18+
pre-commit install
1719

18-
# Save to file
19-
python repomap.py . > repomap.txt
20+
# Manual update (if needed)
21+
./scripts/update-repomap.sh
2022

21-
# Map specific directory with verbose output
22-
python repomap.py /path/to/repo --verbose
23+
# Validate repomap is current
24+
./scripts/update-repomap.sh --check
2325
```
2426

27+
**That's it!** The repomap will auto-update when you commit code changes.
28+
2529
## Installation
2630

2731
### Requirements
@@ -32,11 +36,11 @@ python repomap.py /path/to/repo --verbose
3236
### Install Dependencies
3337

3438
```bash
35-
# Using pip
36-
pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
37-
38-
# Using uv (recommended)
39+
# Recommended method
3940
uv pip install -r requirements.txt
41+
42+
# Or install individually with uv
43+
uv pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
4044
```
4145

4246
## Usage
@@ -165,7 +169,9 @@ jobs:
165169
python-version: '3.11'
166170

167171
- name: Install dependencies
168-
run: pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
172+
run: |
173+
pip install uv
174+
uv pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
169175
170176
- name: Generate repomap
171177
run: python repomap.py . > repomap.txt
@@ -185,14 +191,87 @@ generate_repomap:
185191
stage: build
186192
image: python:3.11
187193
script:
188-
- pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
194+
- pip install uv
195+
- uv pip install tree-sitter tree-sitter-python tree-sitter-javascript tree-sitter-typescript tree-sitter-go tree-sitter-bash
189196
- python repomap.py . > repomap.txt
190197
artifacts:
191198
paths:
192199
- repomap.txt
193200
```
194201
195-
### 3. Pre-commit Hook
202+
### 3. Automated Workflow (This Repository)
203+
204+
This reference repository includes **complete repomap automation**:
205+
206+
#### Pre-commit Hook
207+
208+
The pre-commit hook automatically regenerates `.repomap.txt` when you commit changes to code files:
209+
210+
```yaml
211+
# .pre-commit-config.yaml
212+
repos:
213+
- repo: local
214+
hooks:
215+
- id: repomap-update
216+
name: Update repository map
217+
entry: scripts/update-repomap.sh
218+
language: system
219+
pass_filenames: false
220+
files: '\.(py|js|ts|tsx|go|sh|bash)$'
221+
```
222+
223+
**Triggers on**: `.py`, `.js`, `.ts`, `.tsx`, `.go`, `.sh`, `.bash` file changes
224+
225+
**What it does**: Runs `./scripts/update-repomap.sh` to regenerate `.repomap.txt` before commit
226+
227+
#### CI Validation
228+
229+
GitHub Actions workflow validates repomap is current on every push/PR:
230+
231+
```yaml
232+
# .github/workflows/ci.yml
233+
repomap-validation:
234+
runs-on: ubuntu-latest
235+
steps:
236+
- uses: actions/checkout@v4
237+
- name: Set up Python
238+
uses: actions/setup-python@v5
239+
with:
240+
python-version: '3.11'
241+
- name: Install repomap dependencies
242+
run: |
243+
pip install uv
244+
uv pip install tree-sitter tree-sitter-python tree-sitter-javascript \
245+
tree-sitter-typescript tree-sitter-go tree-sitter-bash
246+
- name: Validate repomap is current
247+
run: ./scripts/update-repomap.sh --check
248+
```
249+
250+
**What it does**: Blocks merge if `.repomap.txt` is outdated
251+
252+
#### Automation Script
253+
254+
The `scripts/update-repomap.sh` script provides:
255+
256+
```bash
257+
# Regenerate repomap
258+
./scripts/update-repomap.sh
259+
260+
# Validate repomap is current (CI usage)
261+
./scripts/update-repomap.sh --check
262+
263+
# Show help
264+
./scripts/update-repomap.sh --help
265+
```
266+
267+
**Features**:
268+
- Clear error messages with dependency installation hints
269+
- Validates repomap currency for CI/CD
270+
- Used by pre-commit hook for auto-updates
271+
272+
#### Manual Pre-commit Hook (Alternative)
273+
274+
If you prefer a simpler manual hook in other repositories:
196275

197276
```bash
198277
# .git/hooks/pre-commit
@@ -267,7 +346,7 @@ Potential improvements for future versions:
267346
**Solution**: Install dependencies
268347

269348
```bash
270-
pip install -r requirements.txt
349+
uv pip install -r requirements.txt
271350
```
272351

273352
### Parse Errors
@@ -320,6 +399,14 @@ See LICENSE file in repository root.
320399

321400
**Quickstart**:
322401

323-
1. Install: `pip install -r requirements.txt`
324-
2. Run: `python repomap.py .`
325-
3. Save: `python repomap.py . > repomap.txt`
402+
1. Install dependencies: `uv pip install -r requirements.txt`
403+
2. Install pre-commit hooks: `pre-commit install`
404+
3. The repomap auto-updates on commits!
405+
406+
**Manual usage** (if needed):
407+
408+
```bash
409+
./scripts/update-repomap.sh # Regenerate
410+
./scripts/update-repomap.sh --check # Validate
411+
python repomap.py . # Direct generation
412+
```

0 commit comments

Comments
 (0)