reforge-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reforge_mcp-0.1.0/.claude/settings.json +15 -0
- reforge_mcp-0.1.0/.claude/settings.local.json +7 -0
- reforge_mcp-0.1.0/.gitignore +74 -0
- reforge_mcp-0.1.0/CLAUDE.md +9 -0
- reforge_mcp-0.1.0/LICENSE +21 -0
- reforge_mcp-0.1.0/PKG-INFO +332 -0
- reforge_mcp-0.1.0/README.md +300 -0
- reforge_mcp-0.1.0/pyproject.toml +65 -0
- reforge_mcp-0.1.0/reforge.toml +41 -0
- reforge_mcp-0.1.0/src/reforge_mcp/__init__.py +13 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/__init__.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/adapters/__init__.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/adapters/golang.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/adapters/javascript.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/adapters/python.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/adapters/typescript.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/architecture.py +108 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/dead_code.py +405 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/duplicates.py +251 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/parser.py +1060 -0
- reforge_mcp-0.1.0/src/reforge_mcp/scanner/risk.py +95 -0
- reforge_mcp-0.1.0/src/reforge_mcp/server.py +219 -0
- reforge_mcp-0.1.0/src/reforge_mcp/tools/__init__.py +14 -0
- reforge_mcp-0.1.0/src/reforge_mcp/tools/chunk.py +99 -0
- reforge_mcp-0.1.0/src/reforge_mcp/tools/fix.py +133 -0
- reforge_mcp-0.1.0/src/reforge_mcp/tools/git.py +175 -0
- reforge_mcp-0.1.0/src/reforge_mcp/tools/scan.py +529 -0
- reforge_mcp-0.1.0/src/reforge_mcp/utils/__init__.py +7 -0
- reforge_mcp-0.1.0/src/reforge_mcp/utils/diff.py +81 -0
- reforge_mcp-0.1.0/src/reforge_mcp/utils/security.py +269 -0
- reforge_mcp-0.1.0/src/reforge_mcp/utils/state.py +158 -0
- reforge_mcp-0.1.0/src/reforge_mcp/utils/test_runner.py +7 -0
- reforge_mcp-0.1.0/tests/__init__.py +7 -0
- reforge_mcp-0.1.0/tests/test_architecture.py +68 -0
- reforge_mcp-0.1.0/tests/test_chunk.py +58 -0
- reforge_mcp-0.1.0/tests/test_fix.py +78 -0
- reforge_mcp-0.1.0/tests/test_git.py +91 -0
- reforge_mcp-0.1.0/tests/test_memory.py +81 -0
- reforge_mcp-0.1.0/tests/test_monorepo.py +53 -0
- reforge_mcp-0.1.0/tests/test_risk.py +84 -0
- reforge_mcp-0.1.0/tests/test_scanner.py +71 -0
- reforge_mcp-0.1.0/tests/test_security.py +313 -0
- reforge_mcp-0.1.0/uv.lock +2680 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "Bash",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "CMD=$(python3 -c \"import json,sys; d=json.load(sys.stdin); print(d.get('tool_input',d).get('command',''))\" 2>/dev/null || true); case \"$CMD\" in *grep*|*rg\\ *|*ripgrep*|*find\\ *|*fd\\ *|*ack\\ *|*ag\\ *) [ -f graphify-out/graph.json ] && echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files.\"}}' || true ;; esac"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Environments
|
|
54
|
+
.env
|
|
55
|
+
.venv
|
|
56
|
+
env/
|
|
57
|
+
venv/
|
|
58
|
+
ENV/
|
|
59
|
+
env.bak/
|
|
60
|
+
venv.bak/
|
|
61
|
+
|
|
62
|
+
# IDE
|
|
63
|
+
.idea/
|
|
64
|
+
.vscode/
|
|
65
|
+
*.swp
|
|
66
|
+
*.swo
|
|
67
|
+
*~
|
|
68
|
+
|
|
69
|
+
# reforge-mcp state files
|
|
70
|
+
reforge-state.json
|
|
71
|
+
.reforge*
|
|
72
|
+
reforge-state.json.bak.*
|
|
73
|
+
REFORGE_CHANGES.md
|
|
74
|
+
graphify-out/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
## graphify
|
|
2
|
+
|
|
3
|
+
This project has a graphify knowledge graph at graphify-out/.
|
|
4
|
+
|
|
5
|
+
Rules:
|
|
6
|
+
- Before answering architecture or codebase questions, read graphify-out/GRAPH_REPORT.md for god nodes and community structure
|
|
7
|
+
- If graphify-out/wiki/index.md exists, navigate it instead of reading raw files
|
|
8
|
+
- For cross-module "how does X relate to Y" questions, prefer `graphify query "<question>"`, `graphify path "<A>" "<B>"`, or `graphify explain "<concept>"` over grep — these traverse the graph's EXTRACTED + INFERRED edges instead of scanning files
|
|
9
|
+
- After modifying code files in this session, run `graphify update .` to keep the graph current (AST-only, no API cost)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 reforge-mcp contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reforge-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server that automatically cleans up messy vibe-coded repositories
|
|
5
|
+
Project-URL: Homepage, https://github.com/codewithaiyan/reforge-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/codewithaiyan/reforge-mcp
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/codewithaiyan/reforge-mcp/issues
|
|
8
|
+
Author: Codewithaiyan
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ast,claude,code-quality,dead-code,mcp,refactoring,static-analysis
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: fastmcp>=0.1.0
|
|
23
|
+
Requires-Dist: gitpython>=3.1.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
26
|
+
Requires-Dist: tree-sitter-go>=0.25.0
|
|
27
|
+
Requires-Dist: tree-sitter-javascript>=0.25.0
|
|
28
|
+
Requires-Dist: tree-sitter-python>=0.25.0
|
|
29
|
+
Requires-Dist: tree-sitter-typescript>=0.23.2
|
|
30
|
+
Requires-Dist: tree-sitter>=0.24.0
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+

|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
# reforge-mcp
|
|
38
|
+
|
|
39
|
+
An MCP server that connects Claude Code to your codebase and systematically cleans it up — scanning, planning, and applying fixes with full rollback safety.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## What it does
|
|
44
|
+
|
|
45
|
+
Vibe-coded repos accumulate fast: functions nobody calls, copy-pasted logic in three files, one 900-line god module that does everything, circular imports that break at runtime. Spotting this manually takes hours; fixing it safely takes longer. `reforge-mcp` exposes your codebase to Claude Code as a set of structured tools so it can analyse, prioritise, and apply fixes autonomously — one atomic commit at a time.
|
|
46
|
+
|
|
47
|
+
### The 7 MCP tools
|
|
48
|
+
|
|
49
|
+
| Tool | What it does |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `scan_repo` | AST-parses your repo (Python, JS, TS, Go) and returns dead code, duplicates, god files, circular deps, and monorepo subprojects |
|
|
52
|
+
| `get_chunk` | Reads an exact line-range slice from any file — lets Claude fetch only what it needs without blowing its context window |
|
|
53
|
+
| `write_fix` | Applies a unified diff atomically, runs optional tests, and auto-rolls back on failure |
|
|
54
|
+
| `git_commit` | Stages and commits specific files; enforces a per-session budget and confirmation checkpoints |
|
|
55
|
+
| `read_memory` | Reads a value from `reforge-state.json` — persists architecture hypotheses, pending fixes, and embeddings across sessions |
|
|
56
|
+
| `write_memory` | Writes any value atomically to `reforge-state.json` |
|
|
57
|
+
| `get_health_score` | Computes a 0–100 health score from scan metrics and appends a timestamped entry to the project's health history |
|
|
58
|
+
|
|
59
|
+
### Also included
|
|
60
|
+
|
|
61
|
+
- **Health score trending** — every `get_health_score` call appends to `health_history` so you can chart improvement over time
|
|
62
|
+
- **Persistent memory** — `reforge-state.json` survives across Claude Code sessions; stores architecture hypotheses, fix logs, pending work
|
|
63
|
+
- **Monorepo support** — `scan_repo` detects Python, JavaScript, TypeScript, and Go subprojects from their marker files and returns the correct `test_command` per subproject
|
|
64
|
+
- **Changelog generation** — `REFORGE_CHANGES.md` is written on demand with score deltas, applied fixes, and pending items
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
**Prerequisites:** Python 3.11+, Claude Code CLI, Git
|
|
71
|
+
|
|
72
|
+
### From PyPI (recommended)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install reforge-mcp
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### From source
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# 1. Clone the repo
|
|
82
|
+
git clone https://github.com/codewithaiyan/reforge-mcp.git
|
|
83
|
+
cd reforge-mcp
|
|
84
|
+
|
|
85
|
+
# 2. Create and activate a virtual environment
|
|
86
|
+
python3 -m venv venv
|
|
87
|
+
source venv/bin/activate # Windows: venv\Scripts\activate
|
|
88
|
+
|
|
89
|
+
# 3. Install in editable mode
|
|
90
|
+
pip install -e .
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Find the absolute path to the server entry point
|
|
95
|
+
which reforge-mcp # e.g. /home/you/.local/bin/reforge-mcp
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Add to `claude_desktop_config.json`** (usually `~/.config/claude/claude_desktop_config.json` on Linux, `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"reforge-mcp": {
|
|
104
|
+
"command": "/home/you/reforge-mcp/venv/bin/reforge-mcp",
|
|
105
|
+
"args": [],
|
|
106
|
+
"env": {}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Replace the path with the output of `which reforge-mcp` from step 4.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 5. Set your Anthropic API key (if not already set)
|
|
116
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Restart Claude Code. The seven tools will appear under the MCP panel.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Usage
|
|
124
|
+
|
|
125
|
+
### Example session with Claude Code
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
You: Use reforge-mcp to scan my repo at /home/me/myproject and fix the top issues.
|
|
129
|
+
|
|
130
|
+
Claude: I'll start with a full scan.
|
|
131
|
+
|
|
132
|
+
[calls scan_repo("/home/me/myproject")]
|
|
133
|
+
|
|
134
|
+
The scan found:
|
|
135
|
+
- 14 dead functions across 6 files
|
|
136
|
+
- 3 duplicate implementations of `calculate_discount`
|
|
137
|
+
- 1 god file: src/api/handlers.py (847 lines, 23 exports)
|
|
138
|
+
- 2 circular dependencies: auth → middleware → auth
|
|
139
|
+
|
|
140
|
+
Health score: 47/100
|
|
141
|
+
|
|
142
|
+
Let me fetch the duplicate implementations to confirm they're identical.
|
|
143
|
+
|
|
144
|
+
[calls get_chunk("src/billing/utils.py", start_line=12, end_line=28)]
|
|
145
|
+
[calls get_chunk("src/cart/helpers.py", start_line=5, end_line=21)]
|
|
146
|
+
|
|
147
|
+
Confirmed — identical bodies. I'll consolidate them into src/shared/pricing.py and
|
|
148
|
+
remove both originals.
|
|
149
|
+
|
|
150
|
+
[calls write_fix("src/shared/pricing.py", diff_str="...")]
|
|
151
|
+
[calls write_fix("src/billing/utils.py", diff_str="...")]
|
|
152
|
+
[calls write_fix("src/cart/helpers.py", diff_str="...")]
|
|
153
|
+
[calls git_commit("/home/me/myproject", files=[...], message="refactor: consolidate duplicate calculate_discount")]
|
|
154
|
+
|
|
155
|
+
Committed: a3f91c2. Running next fix...
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Sample `scan_repo` output
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"summary": {
|
|
163
|
+
"total_files": 42,
|
|
164
|
+
"total_functions": 187,
|
|
165
|
+
"total_lines": 8304,
|
|
166
|
+
"languages_detected": ["python"]
|
|
167
|
+
},
|
|
168
|
+
"dead_code": [
|
|
169
|
+
{ "symbol": "parse_legacy_csv", "file": "src/importers/csv.py", "line": 44 },
|
|
170
|
+
{ "symbol": "_old_validate", "file": "src/models/user.py", "line": 112 }
|
|
171
|
+
],
|
|
172
|
+
"duplicates": [
|
|
173
|
+
{
|
|
174
|
+
"hash": "a3f2...91bc",
|
|
175
|
+
"locations": [
|
|
176
|
+
{ "file": "src/billing/utils.py", "line": 12, "name": "calculate_discount" },
|
|
177
|
+
{ "file": "src/cart/helpers.py", "line": 5, "name": "calculate_discount" },
|
|
178
|
+
{ "file": "src/orders/pricing.py", "line": 78, "name": "apply_discount" }
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"god_files": [
|
|
183
|
+
{ "file": "src/api/handlers.py", "lines": 847, "exports": 23 }
|
|
184
|
+
],
|
|
185
|
+
"dep_graph": {
|
|
186
|
+
"nodes": ["src/auth/__init__.py", "src/middleware/auth.py"],
|
|
187
|
+
"edges": [{ "from": "src/auth/__init__.py", "to": "src/middleware/auth.py" }],
|
|
188
|
+
"circular": [
|
|
189
|
+
["src/auth/__init__.py", "src/middleware/auth.py", "src/auth/__init__.py"]
|
|
190
|
+
]
|
|
191
|
+
},
|
|
192
|
+
"subprojects": [
|
|
193
|
+
{ "root": "services/worker", "language": "go", "test_command": "go test ./..." },
|
|
194
|
+
{ "root": "frontend", "language": "javascript", "test_command": "npm test" }
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Sample `REFORGE_CHANGES.md`
|
|
200
|
+
|
|
201
|
+
```markdown
|
|
202
|
+
# Reforge Changes
|
|
203
|
+
|
|
204
|
+
*Generated: 2025-05-02T14:33:00+00:00*
|
|
205
|
+
|
|
206
|
+
**Health score:** 73.5 (+26.5 from previous scan)
|
|
207
|
+
|
|
208
|
+
## Fixes Applied
|
|
209
|
+
|
|
210
|
+
- refactor: consolidate duplicate calculate_discount
|
|
211
|
+
- fix: remove dead parse_legacy_csv from src/importers/csv.py
|
|
212
|
+
- refactor: split handlers.py into auth_handlers.py and order_handlers.py
|
|
213
|
+
|
|
214
|
+
## Pending Fixes
|
|
215
|
+
|
|
216
|
+
- resolve circular dep: src/auth/__init__.py ↔ src/middleware/auth.py
|
|
217
|
+
- remove _old_validate from src/models/user.py
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## How it works
|
|
223
|
+
|
|
224
|
+
Reforge works in three phases:
|
|
225
|
+
|
|
226
|
+
### 1. Scan
|
|
227
|
+
|
|
228
|
+
`scan_repo` walks the repository with `parse_directory`, feeding each source file to the appropriate tree-sitter adapter (Python, JavaScript/TypeScript, or Go). Tree-sitter builds a full AST — unlike regex, it understands nested scope, decorators, arrow functions, and generics. The adapters extract functions, classes, and imports into typed dataclasses.
|
|
229
|
+
|
|
230
|
+
From the parse results, three analyses run in sequence:
|
|
231
|
+
|
|
232
|
+
- **Dead code** — symbols defined but never referenced anywhere in the repo
|
|
233
|
+
- **Duplicates** — functions whose normalised bodies share the same SHA-256 hash
|
|
234
|
+
- **God files** — files exceeding 500 lines or 10 exported symbols
|
|
235
|
+
|
|
236
|
+
A dependency graph is built from resolved imports and checked for cycles with DFS. Monorepo subprojects are discovered by scanning subdirectories for marker files (`pyproject.toml`, `package.json`, `go.mod`, `tsconfig.json`).
|
|
237
|
+
|
|
238
|
+
### 2. Plan
|
|
239
|
+
|
|
240
|
+
Claude Code receives the structured scan report and uses `get_chunk` to read specific line ranges before deciding what to fix and in what order. The architecture hypothesis, pending fix queue, and health history are all persisted in `reforge-state.json` via `read_memory` / `write_memory` so the plan survives a session restart.
|
|
241
|
+
|
|
242
|
+
### 3. Fix
|
|
243
|
+
|
|
244
|
+
`write_fix` applies a unified diff atomically:
|
|
245
|
+
|
|
246
|
+
1. Creates a `.bak` backup of the target file
|
|
247
|
+
2. Best-effort `git stash` before touching the working tree
|
|
248
|
+
3. Parses the diff into hunks and applies them with line-offset tracking
|
|
249
|
+
4. Runs the optional test command (validated against the allowlist)
|
|
250
|
+
5. On any failure — diff parse error, test exit ≠ 0 — restores from `.bak` and returns `rolled_back: true`
|
|
251
|
+
|
|
252
|
+
`git_commit` stages only the listed files and creates an atomic commit via GitPython. It reads `session_budget` and `confirm_every` from `reforge.toml` and enforces them: once the session budget is exceeded commits are blocked; at every `confirm_every` checkpoint the tool returns `needs_confirmation: true` and waits for `confirmed: true` before proceeding.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Security
|
|
257
|
+
|
|
258
|
+
| Boundary | Mechanism |
|
|
259
|
+
|---|---|
|
|
260
|
+
| Path traversal | Every file path is validated against `repo_root` before any read or write — paths that escape the repo root are rejected with `SecurityError` |
|
|
261
|
+
| Binary / lock files | `should_skip_file()` blocks binary files, `package-lock.json`, `.yarn.lock`, and files over 10 MB before any processing |
|
|
262
|
+
| Test command injection | `write_fix` validates `test_command` against an explicit allowlist (`pytest`, `python3 -m pytest`, `npm test`, `go test ./...`, etc.) before executing |
|
|
263
|
+
| Atomic state writes | `reforge-state.json` is always written via `.tmp` → `rename` — a crash mid-write leaves an orphaned `.tmp`, not a corrupt file; `startup_tasks()` cleans these on boot |
|
|
264
|
+
| Pre-fix stash | `write_fix` attempts `git stash` before touching the working tree; on rollback the stash is discarded, leaving the repo clean |
|
|
265
|
+
| No network calls | The server makes zero outbound network requests; all analysis is local |
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Contributing
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Clone and install
|
|
273
|
+
git clone https://github.com/your-org/reforge-mcp.git
|
|
274
|
+
cd reforge-mcp
|
|
275
|
+
python3 -m venv venv && source venv/bin/activate
|
|
276
|
+
pip install -e .
|
|
277
|
+
pip install pytest pytest-cov
|
|
278
|
+
|
|
279
|
+
# Run the full test suite
|
|
280
|
+
pytest
|
|
281
|
+
|
|
282
|
+
# Run with coverage
|
|
283
|
+
pytest --cov=src --cov-report=term-missing
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Project structure
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
reforge-mcp/
|
|
290
|
+
├── src/reforge_mcp/
|
|
291
|
+
│ ├── server.py # FastMCP server — registers all 7 tools
|
|
292
|
+
│ ├── tools/
|
|
293
|
+
│ │ ├── scan.py # scan_repo, get_health_score, monorepo detection
|
|
294
|
+
│ │ ├── chunk.py # get_chunk — line-range file reads
|
|
295
|
+
│ │ ├── fix.py # write_fix — diff apply + rollback
|
|
296
|
+
│ │ └── git.py # git_commit — atomic commits with budget enforcement
|
|
297
|
+
│ ├── scanner/
|
|
298
|
+
│ │ ├── parser.py # tree-sitter adapters (Python, JS/TS, Go) + QueryCursor wiring
|
|
299
|
+
│ │ ├── dead_code.py # unused symbol detection
|
|
300
|
+
│ │ ├── duplicates.py # body-hash duplicate detection
|
|
301
|
+
│ │ └── adapters/ # per-language project-detection stubs
|
|
302
|
+
│ └── utils/
|
|
303
|
+
│ ├── state.py # reforge-state.json load/save, gitignore, changelog
|
|
304
|
+
│ ├── security.py # path validation, file guard, command allowlist
|
|
305
|
+
│ └── diff.py # unified diff parser and applier
|
|
306
|
+
├── tests/
|
|
307
|
+
│ ├── test_scanner.py
|
|
308
|
+
│ ├── test_chunk.py
|
|
309
|
+
│ ├── test_fix.py
|
|
310
|
+
│ ├── test_git.py
|
|
311
|
+
│ ├── test_memory.py
|
|
312
|
+
│ └── test_monorepo.py
|
|
313
|
+
├── pyproject.toml
|
|
314
|
+
└── reforge.toml # optional per-repo config
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### `reforge.toml` reference
|
|
318
|
+
|
|
319
|
+
```toml
|
|
320
|
+
[fix]
|
|
321
|
+
session_budget = 20 # max commits per Claude session before hard stop
|
|
322
|
+
confirm_every = 5 # pause for confirmation every N commits
|
|
323
|
+
|
|
324
|
+
[scan]
|
|
325
|
+
ignore_dirs = ["generated", "vendor"]
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## License
|
|
331
|
+
|
|
332
|
+
MIT — see [LICENSE](LICENSE).
|