Skip to content

Commit fab1d8f

Browse files
jeremyederclaude
andcommitted
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>
1 parent e2021e2 commit fab1d8f

File tree

7 files changed

+457
-14
lines changed

7 files changed

+457
-14
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ 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 tree-sitter tree-sitter-python tree-sitter-javascript \
39+
tree-sitter-typescript tree-sitter-go tree-sitter-bash
40+
41+
- name: Validate repomap is current
42+
run: |
43+
chmod +x scripts/update-repomap.sh
44+
./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**:
@@ -369,6 +383,7 @@ Focus on "why" rather than "what".
369383
3. **`.github/workflows/ci.yml`** (General CI)
370384
- Code example linting (if any)
371385
- Documentation build test
386+
- Repomap validation (ensures .repomap.txt is current)
372387
- Triggers: on push, PR
373388

374389
4. **`.github/workflows/deploy-docs.yml`** (Documentation Deployment)
@@ -408,9 +423,15 @@ Teams can extend with:
408423
git clone https://github.com/yourusername/reference.git
409424
cd reference
410425

426+
# Install repomap dependencies
427+
uv pip install -r requirements.txt
428+
411429
# Install doc tooling
412430
uv pip install -r requirements-dev.txt
413431

432+
# Install pre-commit hooks
433+
pre-commit install
434+
414435
# Load repomap (session start)
415436
cat .repomap.txt
416437

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+
pip install -r requirements.txt # Repomap dependencies
31+
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: 94 additions & 11 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
14+
# Install dependencies (includes tree-sitter packages)
1315
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
@@ -192,7 +196,78 @@ generate_repomap:
192196
- repomap.txt
193197
```
194198
195-
### 3. Pre-commit Hook
199+
### 3. Automated Workflow (This Repository)
200+
201+
This reference repository includes **complete repomap automation**:
202+
203+
#### Pre-commit Hook
204+
205+
The pre-commit hook automatically regenerates `.repomap.txt` when you commit changes to code files:
206+
207+
```yaml
208+
# .pre-commit-config.yaml
209+
repos:
210+
- repo: local
211+
hooks:
212+
- id: repomap-update
213+
name: Update repository map
214+
entry: scripts/update-repomap.sh
215+
language: system
216+
pass_filenames: false
217+
files: '\.(py|js|ts|tsx|go|sh|bash)$'
218+
```
219+
220+
**Triggers on**: `.py`, `.js`, `.ts`, `.tsx`, `.go`, `.sh`, `.bash` file changes
221+
222+
**What it does**: Runs `./scripts/update-repomap.sh` to regenerate `.repomap.txt` before commit
223+
224+
#### CI Validation
225+
226+
GitHub Actions workflow validates repomap is current on every push/PR:
227+
228+
```yaml
229+
# .github/workflows/ci.yml
230+
repomap-validation:
231+
runs-on: ubuntu-latest
232+
steps:
233+
- uses: actions/checkout@v4
234+
- name: Set up Python
235+
uses: actions/setup-python@v5
236+
with:
237+
python-version: '3.11'
238+
- name: Install repomap dependencies
239+
run: |
240+
pip install tree-sitter tree-sitter-python tree-sitter-javascript \
241+
tree-sitter-typescript tree-sitter-go tree-sitter-bash
242+
- name: Validate repomap is current
243+
run: ./scripts/update-repomap.sh --check
244+
```
245+
246+
**What it does**: Blocks merge if `.repomap.txt` is outdated
247+
248+
#### Automation Script
249+
250+
The `scripts/update-repomap.sh` script provides:
251+
252+
```bash
253+
# Regenerate repomap
254+
./scripts/update-repomap.sh
255+
256+
# Validate repomap is current (CI usage)
257+
./scripts/update-repomap.sh --check
258+
259+
# Show help
260+
./scripts/update-repomap.sh --help
261+
```
262+
263+
**Features**:
264+
- Clear error messages with dependency installation hints
265+
- Validates repomap currency for CI/CD
266+
- Used by pre-commit hook for auto-updates
267+
268+
#### Manual Pre-commit Hook (Alternative)
269+
270+
If you prefer a simpler manual hook in other repositories:
196271

197272
```bash
198273
# .git/hooks/pre-commit
@@ -320,6 +395,14 @@ See LICENSE file in repository root.
320395

321396
**Quickstart**:
322397

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

scripts/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Scripts Directory
2+
3+
Automation scripts for the Ambient Code reference repository.
4+
5+
## Repomap Management
6+
7+
### `update-repomap.sh`
8+
9+
Updates or validates the repository map (`.repomap.txt`) - an AI-friendly code structure map that optimizes context window usage.
10+
11+
**Usage:**
12+
13+
```bash
14+
# Regenerate repomap
15+
./scripts/update-repomap.sh
16+
17+
# Validate repomap is current (CI usage)
18+
./scripts/update-repomap.sh --check
19+
20+
# Show help
21+
./scripts/update-repomap.sh --help
22+
```
23+
24+
**Features:**
25+
26+
- Automatically regenerates `.repomap.txt` using `repomap.py`
27+
- Validates that repomap is current (useful for CI)
28+
- Clear error messages with dependency installation hints
29+
- Used by pre-commit hook to auto-update on code changes
30+
31+
**When to use:**
32+
33+
- After adding/removing files or functions
34+
- Before creating pull requests
35+
- When structural changes occur
36+
- Automatically triggered by pre-commit hook
37+
38+
**Dependencies:** Installed via `requirements.txt`:
39+
40+
```bash
41+
uv pip install -r requirements.txt
42+
```
43+
44+
## Documentation Validation
45+
46+
### `validate-mermaid.sh`
47+
48+
Validates all Mermaid diagrams in the documentation.
49+
50+
**Usage:**
51+
52+
```bash
53+
./scripts/validate-mermaid.sh
54+
```
55+
56+
**Purpose:** Ensures Mermaid diagrams are syntactically correct before committing, preventing broken diagrams in documentation.
57+
58+
## Development Setup
59+
60+
### `setup.sh`
61+
62+
Initial repository setup script.
63+
64+
**Usage:**
65+
66+
```bash
67+
./scripts/setup.sh
68+
```
69+
70+
**What it does:**
71+
72+
- Installs dependencies
73+
- Sets up pre-commit hooks
74+
- Initializes development environment
75+
76+
## Demo Recording
77+
78+
### `record-demo.sh`
79+
80+
Records demonstration videos/screenshots for documentation.
81+
82+
**Usage:**
83+
84+
```bash
85+
./scripts/record-demo.sh
86+
```
87+
88+
## Autonomous Review
89+
90+
Scripts for automated code review workflows.
91+
92+
### `autonomous-review/review-reference.sh`
93+
94+
Performs automated review of reference documentation.
95+
96+
**Usage:**
97+
98+
```bash
99+
./scripts/autonomous-review/review-reference.sh
100+
```
101+
102+
## Validation
103+
104+
Scripts for continuous validation and testing.
105+
106+
### `validation/autonomous-fix-loop-template.sh`
107+
108+
Template for autonomous validation and fix loops.
109+
110+
### `validation/tests/`
111+
112+
Test scripts for validation workflows:
113+
114+
- `run-all.sh` - Run all validation tests
115+
- `test-autonomous-fix-loop.sh` - Test autonomous fix loop
116+
117+
## Quick Reference
118+
119+
**Common workflows:**
120+
121+
```bash
122+
# Setup new development environment
123+
./scripts/setup.sh
124+
125+
# Update repomap after code changes
126+
./scripts/update-repomap.sh
127+
128+
# Validate documentation
129+
./scripts/validate-mermaid.sh
130+
markdownlint docs/**/*.md --fix
131+
132+
# Run all validation tests
133+
./scripts/validation/tests/run-all.sh
134+
```
135+
136+
## CI Integration
137+
138+
These scripts are integrated into GitHub Actions workflows:
139+
140+
- **`update-repomap.sh --check`** - CI job validates repomap is current
141+
- **`validate-mermaid.sh`** - CI job validates diagrams before merge
142+
- **Pre-commit hook** - Auto-runs `update-repomap.sh` on code changes
143+
144+
## Development Notes
145+
146+
- All scripts use `#!/usr/bin/env bash` for portability
147+
- Scripts include error handling (`set -euo pipefail`)
148+
- Scripts provide helpful error messages with actionable suggestions
149+
- Scripts follow the "fail fast" principle

0 commit comments

Comments
 (0)