pfix 0.1.1__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.
- pfix-0.1.1/.gitignore +218 -0
- pfix-0.1.1/CHANGELOG.md +26 -0
- pfix-0.1.1/LICENSE +15 -0
- pfix-0.1.1/PKG-INFO +232 -0
- pfix-0.1.1/README.md +185 -0
- pfix-0.1.1/VERSION +1 -0
- pfix-0.1.1/examples/demo.py +44 -0
- pfix-0.1.1/goal.yaml +512 -0
- pfix-0.1.1/mcp-config.json +11 -0
- pfix-0.1.1/pyproject.toml +77 -0
- pfix-0.1.1/src/pfix/__init__.py +21 -0
- pfix-0.1.1/src/pfix/analyzer.py +223 -0
- pfix-0.1.1/src/pfix/cli.py +220 -0
- pfix-0.1.1/src/pfix/config.py +151 -0
- pfix-0.1.1/src/pfix/decorator.py +265 -0
- pfix-0.1.1/src/pfix/dependency.py +205 -0
- pfix-0.1.1/src/pfix/fixer.py +200 -0
- pfix-0.1.1/src/pfix/llm.py +135 -0
- pfix-0.1.1/src/pfix/mcp_client.py +81 -0
- pfix-0.1.1/src/pfix/mcp_server.py +215 -0
- pfix-0.1.1/tests/test_pfix.py +250 -0
pfix-0.1.1/.gitignore
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
.env.example
|
|
2
|
+
.idea
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.mypy_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
.venv/
|
|
12
|
+
# Byte-compiled / optimized / DLL files
|
|
13
|
+
__pycache__/
|
|
14
|
+
*.py[codz]
|
|
15
|
+
*$py.class
|
|
16
|
+
|
|
17
|
+
# C extensions
|
|
18
|
+
*.so
|
|
19
|
+
|
|
20
|
+
# Distribution / packaging
|
|
21
|
+
.Python
|
|
22
|
+
build/
|
|
23
|
+
develop-eggs/
|
|
24
|
+
dist/
|
|
25
|
+
downloads/
|
|
26
|
+
eggs/
|
|
27
|
+
.eggs/
|
|
28
|
+
lib/
|
|
29
|
+
lib64/
|
|
30
|
+
parts/
|
|
31
|
+
sdist/
|
|
32
|
+
var/
|
|
33
|
+
wheels/
|
|
34
|
+
share/python-wheels/
|
|
35
|
+
*.egg-info/
|
|
36
|
+
.installed.cfg
|
|
37
|
+
*.egg
|
|
38
|
+
MANIFEST
|
|
39
|
+
|
|
40
|
+
# PyInstaller
|
|
41
|
+
# Usually these files are written by a python script from a template
|
|
42
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
43
|
+
*.manifest
|
|
44
|
+
*.spec
|
|
45
|
+
|
|
46
|
+
# Installer logs
|
|
47
|
+
pip-log.txt
|
|
48
|
+
pip-delete-this-directory.txt
|
|
49
|
+
|
|
50
|
+
# Unit test / coverage reports
|
|
51
|
+
htmlcov/
|
|
52
|
+
.tox/
|
|
53
|
+
.nox/
|
|
54
|
+
.coverage
|
|
55
|
+
.coverage.*
|
|
56
|
+
.cache
|
|
57
|
+
nosetests.xml
|
|
58
|
+
coverage.xml
|
|
59
|
+
*.cover
|
|
60
|
+
*.py.cover
|
|
61
|
+
.hypothesis/
|
|
62
|
+
.pytest_cache/
|
|
63
|
+
cover/
|
|
64
|
+
|
|
65
|
+
# Translations
|
|
66
|
+
*.mo
|
|
67
|
+
*.pot
|
|
68
|
+
|
|
69
|
+
# Django stuff:
|
|
70
|
+
*.log
|
|
71
|
+
local_settings.py
|
|
72
|
+
db.sqlite3
|
|
73
|
+
db.sqlite3-journal
|
|
74
|
+
|
|
75
|
+
# Flask stuff:
|
|
76
|
+
instance/
|
|
77
|
+
.webassets-cache
|
|
78
|
+
|
|
79
|
+
# Scrapy stuff:
|
|
80
|
+
.scrapy
|
|
81
|
+
|
|
82
|
+
# Sphinx documentation
|
|
83
|
+
docs/_build/
|
|
84
|
+
|
|
85
|
+
# PyBuilder
|
|
86
|
+
.pybuilder/
|
|
87
|
+
target/
|
|
88
|
+
|
|
89
|
+
# Jupyter Notebook
|
|
90
|
+
.ipynb_checkpoints
|
|
91
|
+
|
|
92
|
+
# IPython
|
|
93
|
+
profile_default/
|
|
94
|
+
ipython_config.py
|
|
95
|
+
|
|
96
|
+
# pyenv
|
|
97
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
98
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
99
|
+
# .python-version
|
|
100
|
+
|
|
101
|
+
# pipenv
|
|
102
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
103
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
104
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
105
|
+
# install all needed dependencies.
|
|
106
|
+
#Pipfile.lock
|
|
107
|
+
|
|
108
|
+
# UV
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
110
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
111
|
+
# commonly ignored for libraries.
|
|
112
|
+
#uv.lock
|
|
113
|
+
|
|
114
|
+
# poetry
|
|
115
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
116
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
117
|
+
# commonly ignored for libraries.
|
|
118
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
119
|
+
#poetry.lock
|
|
120
|
+
#poetry.toml
|
|
121
|
+
|
|
122
|
+
# pdm
|
|
123
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
124
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
125
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
126
|
+
#pdm.lock
|
|
127
|
+
#pdm.toml
|
|
128
|
+
.pdm-python
|
|
129
|
+
.pdm-build/
|
|
130
|
+
|
|
131
|
+
# pixi
|
|
132
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
133
|
+
#pixi.lock
|
|
134
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
135
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
136
|
+
.pixi
|
|
137
|
+
|
|
138
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
139
|
+
__pypackages__/
|
|
140
|
+
|
|
141
|
+
# Celery stuff
|
|
142
|
+
celerybeat-schedule
|
|
143
|
+
celerybeat.pid
|
|
144
|
+
|
|
145
|
+
# SageMath parsed files
|
|
146
|
+
*.sage.py
|
|
147
|
+
|
|
148
|
+
# Environments
|
|
149
|
+
.env
|
|
150
|
+
.envrc
|
|
151
|
+
.venv
|
|
152
|
+
env/
|
|
153
|
+
venv/
|
|
154
|
+
ENV/
|
|
155
|
+
env.bak/
|
|
156
|
+
venv.bak/
|
|
157
|
+
|
|
158
|
+
# Spyder project settings
|
|
159
|
+
.spyderproject
|
|
160
|
+
.spyproject
|
|
161
|
+
|
|
162
|
+
# Rope project settings
|
|
163
|
+
.ropeproject
|
|
164
|
+
|
|
165
|
+
# mkdocs documentation
|
|
166
|
+
/site
|
|
167
|
+
|
|
168
|
+
# mypy
|
|
169
|
+
.mypy_cache/
|
|
170
|
+
.dmypy.json
|
|
171
|
+
dmypy.json
|
|
172
|
+
|
|
173
|
+
# Pyre type checker
|
|
174
|
+
.pyre/
|
|
175
|
+
|
|
176
|
+
# pytype static type analyzer
|
|
177
|
+
.pytype/
|
|
178
|
+
|
|
179
|
+
# Cython debug symbols
|
|
180
|
+
cython_debug/
|
|
181
|
+
|
|
182
|
+
# PyCharm
|
|
183
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
184
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
185
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
186
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
187
|
+
#.idea/
|
|
188
|
+
|
|
189
|
+
# Abstra
|
|
190
|
+
# Abstra is an AI-powered process automation framework.
|
|
191
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
192
|
+
# Learn more at https://abstra.io/docs
|
|
193
|
+
.abstra/
|
|
194
|
+
|
|
195
|
+
# Visual Studio Code
|
|
196
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
197
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
198
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
199
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
200
|
+
# .vscode/
|
|
201
|
+
|
|
202
|
+
# Ruff stuff:
|
|
203
|
+
.ruff_cache/
|
|
204
|
+
|
|
205
|
+
# PyPI configuration file
|
|
206
|
+
.pypirc
|
|
207
|
+
|
|
208
|
+
# Cursor
|
|
209
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
210
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
211
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
212
|
+
.cursorignore
|
|
213
|
+
.cursorindexingignore
|
|
214
|
+
|
|
215
|
+
# Marimo
|
|
216
|
+
marimo/_static/
|
|
217
|
+
marimo/_lsp/
|
|
218
|
+
__marimo__/
|
pfix-0.1.1/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.1] - 2026-03-28
|
|
11
|
+
|
|
12
|
+
### Docs
|
|
13
|
+
- Update README.md
|
|
14
|
+
|
|
15
|
+
### Test
|
|
16
|
+
- Update tests/test_pfix.py
|
|
17
|
+
|
|
18
|
+
### Other
|
|
19
|
+
- Update .env.example
|
|
20
|
+
- Update .gitignore
|
|
21
|
+
- Update .idea/.gitignore
|
|
22
|
+
- Update LICENSE
|
|
23
|
+
- Update PKG-INFO
|
|
24
|
+
- Update examples/demo.py
|
|
25
|
+
- Update mcp-config.json
|
|
26
|
+
|
pfix-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Tom Sapletta
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
pfix-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pfix
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Self-healing Python — catches runtime errors, fixes code & dependencies via LLM + MCP
|
|
5
|
+
Project-URL: Homepage, https://github.com/softreck/pfix
|
|
6
|
+
Project-URL: Repository, https://github.com/softreck/pfix
|
|
7
|
+
Project-URL: Issues, https://github.com/softreck/pfix/issues
|
|
8
|
+
Author-email: Tom Sapletta <tom@softreck.dev>, Tom Sapletta <tom@sapletta.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: auto-fix,debugging,developer-tools,llm,mcp,self-healing
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: litellm>=1.40.0
|
|
21
|
+
Requires-Dist: pathspec>=0.12.0
|
|
22
|
+
Requires-Dist: pipreqs>=0.5.0
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: gitpython>=3.1.0; extra == 'all'
|
|
27
|
+
Requires-Dist: httpx>=0.27.0; extra == 'all'
|
|
28
|
+
Requires-Dist: mcp>=1.0.0; extra == 'all'
|
|
29
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'all'
|
|
30
|
+
Requires-Dist: pytest>=8.0; extra == 'all'
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == 'all'
|
|
32
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'all'
|
|
33
|
+
Requires-Dist: watchdog>=4.0.0; extra == 'all'
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
38
|
+
Provides-Extra: git
|
|
39
|
+
Requires-Dist: gitpython>=3.1.0; extra == 'git'
|
|
40
|
+
Provides-Extra: mcp
|
|
41
|
+
Requires-Dist: httpx>=0.27.0; extra == 'mcp'
|
|
42
|
+
Requires-Dist: mcp>=1.0.0; extra == 'mcp'
|
|
43
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'mcp'
|
|
44
|
+
Provides-Extra: watch
|
|
45
|
+
Requires-Dist: watchdog>=4.0.0; extra == 'watch'
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# 🔧 pfix
|
|
49
|
+
|
|
50
|
+
**Self-healing Python** — catches runtime errors and fixes source code + dependencies via LLM + MCP.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **`@pfix` decorator** — wrap any function; errors trigger automatic repair
|
|
55
|
+
- **Fast dep fix** — `ModuleNotFoundError` → instant `pip`/`uv install` (no LLM call)
|
|
56
|
+
- **pipreqs scanning** — project-wide import analysis for missing dependencies
|
|
57
|
+
- **LLM code repair** — sends error context to LLM (OpenRouter/LiteLLM) for intelligent fixes
|
|
58
|
+
- **pip + uv** — auto-detects `uv` for faster installs, falls back to `pip`
|
|
59
|
+
- **MCP server** — `@mcp.tool()` via FastMCP for IDE integration (Claude Code, Cursor, VS Code)
|
|
60
|
+
- **Git auto-commit** — optional auto-commit of fixes with configurable prefix
|
|
61
|
+
- **Auto-restart** — `os.execv` process restart after fix applied
|
|
62
|
+
- **Interactive diff** — unified diff with confirmation before applying
|
|
63
|
+
- **Backup system** — timestamped backups in `.pfix_backups/`
|
|
64
|
+
- **Async support** — `@apfix` for async functions
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install pfix
|
|
70
|
+
|
|
71
|
+
# With MCP server support
|
|
72
|
+
pip install pfix[mcp]
|
|
73
|
+
|
|
74
|
+
# With git auto-commit
|
|
75
|
+
pip install pfix[git]
|
|
76
|
+
|
|
77
|
+
# Everything
|
|
78
|
+
pip install pfix[all]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quick Start
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# 1. Configure
|
|
85
|
+
cp .env.example .env
|
|
86
|
+
# Set OPENROUTER_API_KEY=sk-or-v1-...
|
|
87
|
+
|
|
88
|
+
# 2. Use in your code
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pfix import pfix
|
|
93
|
+
|
|
94
|
+
@pfix
|
|
95
|
+
def process_data(path):
|
|
96
|
+
import pandas as pd # auto-installed if missing
|
|
97
|
+
df = pd.read_csv(path)
|
|
98
|
+
return df.groupby("category").sum() # LLM fixes column errors
|
|
99
|
+
|
|
100
|
+
@pfix(retries=3, hint="Parses ISO dates from API", deps=["requests", "python-dateutil"])
|
|
101
|
+
def fetch_events(url: str):
|
|
102
|
+
import requests
|
|
103
|
+
from dateutil.parser import parse
|
|
104
|
+
return [parse(e["ts"]) for e in requests.get(url).json()["events"]]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## CLI
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pfix run script.py # Run with global exception hook
|
|
111
|
+
pfix run script.py --auto # Auto-apply fixes
|
|
112
|
+
pfix run script.py --restart # Restart process after fix
|
|
113
|
+
pfix check # Show config status
|
|
114
|
+
pfix deps scan # Scan for missing deps (pipreqs)
|
|
115
|
+
pfix deps install # Install all missing deps
|
|
116
|
+
pfix deps generate # Generate requirements.txt
|
|
117
|
+
pfix server # Start MCP server (stdio)
|
|
118
|
+
pfix server --http 3001 # Start MCP server (HTTP)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## MCP Integration
|
|
122
|
+
|
|
123
|
+
pfix exposes tools via FastMCP for IDE integration:
|
|
124
|
+
|
|
125
|
+
| Tool | Description |
|
|
126
|
+
|---|---|
|
|
127
|
+
| `pfix_analyze` | Analyze error → diagnosis + fix proposal |
|
|
128
|
+
| `pfix_fix` | Analyze + apply fix (with backup) |
|
|
129
|
+
| `pfix_deps_scan` | Scan for missing deps |
|
|
130
|
+
| `pfix_deps_install` | Install a package |
|
|
131
|
+
| `pfix_deps_generate` | Generate requirements.txt |
|
|
132
|
+
| `pfix_edit_file` | Write file content |
|
|
133
|
+
|
|
134
|
+
### Claude Code / VS Code setup
|
|
135
|
+
|
|
136
|
+
Add to your MCP config (`.claude/mcp.json` or VS Code settings):
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"mcpServers": {
|
|
141
|
+
"pfix": {
|
|
142
|
+
"command": "python",
|
|
143
|
+
"args": ["-m", "pfix.mcp_server"]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Configuration
|
|
150
|
+
|
|
151
|
+
### .env
|
|
152
|
+
|
|
153
|
+
| Variable | Default | Description |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `OPENROUTER_API_KEY` | — | Required |
|
|
156
|
+
| `PFIX_MODEL` | `openrouter/anthropic/claude-sonnet-4` | LLM model |
|
|
157
|
+
| `PFIX_AUTO_APPLY` | `false` | Auto-apply fixes |
|
|
158
|
+
| `PFIX_AUTO_INSTALL_DEPS` | `true` | Auto pip/uv install |
|
|
159
|
+
| `PFIX_AUTO_RESTART` | `false` | Restart after fix |
|
|
160
|
+
| `PFIX_PKG_MANAGER` | auto | `pip` or `uv` |
|
|
161
|
+
| `PFIX_MAX_RETRIES` | `3` | Max attempts |
|
|
162
|
+
| `PFIX_DRY_RUN` | `false` | Show only |
|
|
163
|
+
| `PFIX_GIT_COMMIT` | `false` | Auto-commit fixes |
|
|
164
|
+
| `PFIX_GIT_PREFIX` | `pfix: ` | Commit prefix |
|
|
165
|
+
|
|
166
|
+
### pyproject.toml
|
|
167
|
+
|
|
168
|
+
```toml
|
|
169
|
+
[tool.pfix]
|
|
170
|
+
model = "openrouter/anthropic/claude-sonnet-4"
|
|
171
|
+
auto_apply = false
|
|
172
|
+
max_retries = 3
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Programmatic
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from pfix import configure
|
|
179
|
+
|
|
180
|
+
configure(
|
|
181
|
+
auto_apply=True,
|
|
182
|
+
pkg_manager="uv",
|
|
183
|
+
git_auto_commit=True,
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## How It Works
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
@pfix decorated function
|
|
191
|
+
│
|
|
192
|
+
▼
|
|
193
|
+
Exception caught
|
|
194
|
+
│
|
|
195
|
+
├── ModuleNotFoundError? → pip/uv install → retry
|
|
196
|
+
│
|
|
197
|
+
▼
|
|
198
|
+
ErrorContext built (traceback, source, vars, imports, pipreqs scan)
|
|
199
|
+
│
|
|
200
|
+
▼
|
|
201
|
+
LLM analysis (LiteLLM → OpenRouter)
|
|
202
|
+
│
|
|
203
|
+
▼
|
|
204
|
+
FixProposal (diagnosis, code, deps, confidence)
|
|
205
|
+
│
|
|
206
|
+
├── Show diff → confirm (or auto-apply)
|
|
207
|
+
├── Create .pfix_backups/ backup
|
|
208
|
+
├── Apply fix to source
|
|
209
|
+
├── Git commit (optional)
|
|
210
|
+
▼
|
|
211
|
+
Reload module → retry (or os.execv restart)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Dependencies
|
|
215
|
+
|
|
216
|
+
| Package | Role |
|
|
217
|
+
|---|---|
|
|
218
|
+
| `litellm` | LLM proxy — OpenRouter, OpenAI, Anthropic, Ollama |
|
|
219
|
+
| `python-dotenv` | Load .env config |
|
|
220
|
+
| `rich` | Terminal UI (diffs, panels, tables) |
|
|
221
|
+
| `pipreqs` | Project import scanning |
|
|
222
|
+
| `pathspec` | Gitignore-aware file filtering |
|
|
223
|
+
| `mcp` | FastMCP server (optional) |
|
|
224
|
+
| `gitpython` | Git auto-commit (optional) |
|
|
225
|
+
| `watchdog` | File change watching (optional) |
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
Licensed under Apache-2.0.
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
Apache 2.0 — Tom Sapletta / Softreck
|
pfix-0.1.1/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# 🔧 pfix
|
|
2
|
+
|
|
3
|
+
**Self-healing Python** — catches runtime errors and fixes source code + dependencies via LLM + MCP.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **`@pfix` decorator** — wrap any function; errors trigger automatic repair
|
|
8
|
+
- **Fast dep fix** — `ModuleNotFoundError` → instant `pip`/`uv install` (no LLM call)
|
|
9
|
+
- **pipreqs scanning** — project-wide import analysis for missing dependencies
|
|
10
|
+
- **LLM code repair** — sends error context to LLM (OpenRouter/LiteLLM) for intelligent fixes
|
|
11
|
+
- **pip + uv** — auto-detects `uv` for faster installs, falls back to `pip`
|
|
12
|
+
- **MCP server** — `@mcp.tool()` via FastMCP for IDE integration (Claude Code, Cursor, VS Code)
|
|
13
|
+
- **Git auto-commit** — optional auto-commit of fixes with configurable prefix
|
|
14
|
+
- **Auto-restart** — `os.execv` process restart after fix applied
|
|
15
|
+
- **Interactive diff** — unified diff with confirmation before applying
|
|
16
|
+
- **Backup system** — timestamped backups in `.pfix_backups/`
|
|
17
|
+
- **Async support** — `@apfix` for async functions
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install pfix
|
|
23
|
+
|
|
24
|
+
# With MCP server support
|
|
25
|
+
pip install pfix[mcp]
|
|
26
|
+
|
|
27
|
+
# With git auto-commit
|
|
28
|
+
pip install pfix[git]
|
|
29
|
+
|
|
30
|
+
# Everything
|
|
31
|
+
pip install pfix[all]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 1. Configure
|
|
38
|
+
cp .env.example .env
|
|
39
|
+
# Set OPENROUTER_API_KEY=sk-or-v1-...
|
|
40
|
+
|
|
41
|
+
# 2. Use in your code
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from pfix import pfix
|
|
46
|
+
|
|
47
|
+
@pfix
|
|
48
|
+
def process_data(path):
|
|
49
|
+
import pandas as pd # auto-installed if missing
|
|
50
|
+
df = pd.read_csv(path)
|
|
51
|
+
return df.groupby("category").sum() # LLM fixes column errors
|
|
52
|
+
|
|
53
|
+
@pfix(retries=3, hint="Parses ISO dates from API", deps=["requests", "python-dateutil"])
|
|
54
|
+
def fetch_events(url: str):
|
|
55
|
+
import requests
|
|
56
|
+
from dateutil.parser import parse
|
|
57
|
+
return [parse(e["ts"]) for e in requests.get(url).json()["events"]]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## CLI
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pfix run script.py # Run with global exception hook
|
|
64
|
+
pfix run script.py --auto # Auto-apply fixes
|
|
65
|
+
pfix run script.py --restart # Restart process after fix
|
|
66
|
+
pfix check # Show config status
|
|
67
|
+
pfix deps scan # Scan for missing deps (pipreqs)
|
|
68
|
+
pfix deps install # Install all missing deps
|
|
69
|
+
pfix deps generate # Generate requirements.txt
|
|
70
|
+
pfix server # Start MCP server (stdio)
|
|
71
|
+
pfix server --http 3001 # Start MCP server (HTTP)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## MCP Integration
|
|
75
|
+
|
|
76
|
+
pfix exposes tools via FastMCP for IDE integration:
|
|
77
|
+
|
|
78
|
+
| Tool | Description |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `pfix_analyze` | Analyze error → diagnosis + fix proposal |
|
|
81
|
+
| `pfix_fix` | Analyze + apply fix (with backup) |
|
|
82
|
+
| `pfix_deps_scan` | Scan for missing deps |
|
|
83
|
+
| `pfix_deps_install` | Install a package |
|
|
84
|
+
| `pfix_deps_generate` | Generate requirements.txt |
|
|
85
|
+
| `pfix_edit_file` | Write file content |
|
|
86
|
+
|
|
87
|
+
### Claude Code / VS Code setup
|
|
88
|
+
|
|
89
|
+
Add to your MCP config (`.claude/mcp.json` or VS Code settings):
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"mcpServers": {
|
|
94
|
+
"pfix": {
|
|
95
|
+
"command": "python",
|
|
96
|
+
"args": ["-m", "pfix.mcp_server"]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
### .env
|
|
105
|
+
|
|
106
|
+
| Variable | Default | Description |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `OPENROUTER_API_KEY` | — | Required |
|
|
109
|
+
| `PFIX_MODEL` | `openrouter/anthropic/claude-sonnet-4` | LLM model |
|
|
110
|
+
| `PFIX_AUTO_APPLY` | `false` | Auto-apply fixes |
|
|
111
|
+
| `PFIX_AUTO_INSTALL_DEPS` | `true` | Auto pip/uv install |
|
|
112
|
+
| `PFIX_AUTO_RESTART` | `false` | Restart after fix |
|
|
113
|
+
| `PFIX_PKG_MANAGER` | auto | `pip` or `uv` |
|
|
114
|
+
| `PFIX_MAX_RETRIES` | `3` | Max attempts |
|
|
115
|
+
| `PFIX_DRY_RUN` | `false` | Show only |
|
|
116
|
+
| `PFIX_GIT_COMMIT` | `false` | Auto-commit fixes |
|
|
117
|
+
| `PFIX_GIT_PREFIX` | `pfix: ` | Commit prefix |
|
|
118
|
+
|
|
119
|
+
### pyproject.toml
|
|
120
|
+
|
|
121
|
+
```toml
|
|
122
|
+
[tool.pfix]
|
|
123
|
+
model = "openrouter/anthropic/claude-sonnet-4"
|
|
124
|
+
auto_apply = false
|
|
125
|
+
max_retries = 3
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Programmatic
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from pfix import configure
|
|
132
|
+
|
|
133
|
+
configure(
|
|
134
|
+
auto_apply=True,
|
|
135
|
+
pkg_manager="uv",
|
|
136
|
+
git_auto_commit=True,
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## How It Works
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
@pfix decorated function
|
|
144
|
+
│
|
|
145
|
+
▼
|
|
146
|
+
Exception caught
|
|
147
|
+
│
|
|
148
|
+
├── ModuleNotFoundError? → pip/uv install → retry
|
|
149
|
+
│
|
|
150
|
+
▼
|
|
151
|
+
ErrorContext built (traceback, source, vars, imports, pipreqs scan)
|
|
152
|
+
│
|
|
153
|
+
▼
|
|
154
|
+
LLM analysis (LiteLLM → OpenRouter)
|
|
155
|
+
│
|
|
156
|
+
▼
|
|
157
|
+
FixProposal (diagnosis, code, deps, confidence)
|
|
158
|
+
│
|
|
159
|
+
├── Show diff → confirm (or auto-apply)
|
|
160
|
+
├── Create .pfix_backups/ backup
|
|
161
|
+
├── Apply fix to source
|
|
162
|
+
├── Git commit (optional)
|
|
163
|
+
▼
|
|
164
|
+
Reload module → retry (or os.execv restart)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Dependencies
|
|
168
|
+
|
|
169
|
+
| Package | Role |
|
|
170
|
+
|---|---|
|
|
171
|
+
| `litellm` | LLM proxy — OpenRouter, OpenAI, Anthropic, Ollama |
|
|
172
|
+
| `python-dotenv` | Load .env config |
|
|
173
|
+
| `rich` | Terminal UI (diffs, panels, tables) |
|
|
174
|
+
| `pipreqs` | Project import scanning |
|
|
175
|
+
| `pathspec` | Gitignore-aware file filtering |
|
|
176
|
+
| `mcp` | FastMCP server (optional) |
|
|
177
|
+
| `gitpython` | Git auto-commit (optional) |
|
|
178
|
+
| `watchdog` | File change watching (optional) |
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
Licensed under Apache-2.0.
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
Apache 2.0 — Tom Sapletta / Softreck
|
pfix-0.1.1/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.1
|