patch-pilot-ai 0.1.0__tar.gz → 1.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.
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/PKG-INFO +68 -10
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/README.md +67 -9
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/__init__.py +1 -1
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/agent.py +26 -3
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/cli.py +1 -1
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/llm.py +40 -28
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/runner.py +31 -1
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/PKG-INFO +68 -10
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/SOURCES.txt +2 -1
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/pyproject.toml +1 -1
- patch_pilot_ai-1.1.0/tests/test_pilot.py +14 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/config.py +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot/git_ops.py +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/dependency_links.txt +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/entry_points.txt +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/requires.txt +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/patch_pilot_ai.egg-info/top_level.txt +0 -0
- {patch_pilot_ai-0.1.0 → patch_pilot_ai-1.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patch-pilot-ai
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Autonomous code healing and bug patching agent powered by Google Gemini.
|
|
5
5
|
Author: Shubhransh Gupta
|
|
6
6
|
License: MIT
|
|
@@ -56,7 +56,7 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
56
56
|
## 🌟 Key Capabilities
|
|
57
57
|
|
|
58
58
|
- **Multi-Model Intelligence**: Fix code using Claude 3.5 Sonnet, GPT-4o, Gemini 2.5, DeepSeek-Coder, or local Ollama.
|
|
59
|
-
- **Automatic Test Runner Detection**: Supports `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
59
|
+
- **Automatic Test Runner Detection**: Supports `swift test` (SPM), `xcodebuild` (iOS/macOS), `fastlane test`, `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
60
60
|
- **Iterative Self-Healing Loop**: If a patch fails the test suite, Patch Pilot captures the exact error tracebacks and re-prompts the model to refine the fix.
|
|
61
61
|
- **Git Branch & Commit Automation**: Automatically isolates changes in a dedicated Git feature branch and writes conventional commit messages upon test verification.
|
|
62
62
|
|
|
@@ -64,25 +64,77 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
64
64
|
|
|
65
65
|
### 1. Installation
|
|
66
66
|
|
|
67
|
+
Install directly from PyPI:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install patch-pilot-ai
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or install from source:
|
|
74
|
+
|
|
67
75
|
```bash
|
|
68
76
|
git clone https://github.com/shubhransh-gupta/patch-pilot.git
|
|
69
77
|
cd patch-pilot
|
|
70
78
|
pip install -e .
|
|
71
79
|
```
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
## 🔄 How to Use in Any Other Project (GitHub Action CI/CD)
|
|
82
|
+
|
|
83
|
+
You can drop **Patch Pilot** directly into **any repository's CI pipeline** to automatically diagnose failing tests and self-heal your code.
|
|
74
84
|
|
|
75
|
-
|
|
85
|
+
Available on the **GitHub Marketplace**: [`shubhransh-gupta/patch-pilot@v1`](https://github.com/shubhransh-gupta/patch-pilot)
|
|
86
|
+
|
|
87
|
+
### 1. Configure Your AI Provider Secret
|
|
88
|
+
In your target repository:
|
|
89
|
+
1. Navigate to **Settings** → **Secrets and variables** → **Actions** → **New repository secret**.
|
|
90
|
+
2. Name the secret `GEMINI_API_KEY` (or `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `DEEPSEEK_API_KEY`) and paste your API key.
|
|
91
|
+
|
|
92
|
+
### 2. Create the Workflow File
|
|
93
|
+
Add a new workflow file at `.github/workflows/self-heal-ci.yml`:
|
|
76
94
|
|
|
77
95
|
```yaml
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
name: Patch Pilot Self-Healing CI
|
|
97
|
+
|
|
98
|
+
on:
|
|
99
|
+
workflow_dispatch:
|
|
100
|
+
issue_comment:
|
|
101
|
+
types: [created]
|
|
102
|
+
|
|
103
|
+
jobs:
|
|
104
|
+
heal:
|
|
105
|
+
# Triggers manually or when a PR comment contains '/heal'
|
|
106
|
+
if: contains(github.event.comment.body, '/heal') || github.event_name == 'workflow_dispatch'
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
permissions:
|
|
109
|
+
contents: write
|
|
110
|
+
pull-requests: write
|
|
111
|
+
|
|
112
|
+
steps:
|
|
113
|
+
- name: Checkout Code
|
|
114
|
+
uses: actions/checkout@v4
|
|
115
|
+
with:
|
|
116
|
+
fetch-depth: 0
|
|
117
|
+
|
|
118
|
+
- name: Run Patch Pilot Self-Healing
|
|
119
|
+
uses: shubhransh-gupta/patch-pilot@v1
|
|
120
|
+
with:
|
|
121
|
+
api-key: ${{ secrets.GEMINI_API_KEY }}
|
|
122
|
+
provider: 'gemini'
|
|
123
|
+
issue: 'Fix failing unit tests in test suite'
|
|
124
|
+
max-attempts: '4'
|
|
84
125
|
```
|
|
85
126
|
|
|
127
|
+
### Action Inputs Reference
|
|
128
|
+
|
|
129
|
+
| Input | Required | Default | Description |
|
|
130
|
+
| :--- | :--- | :--- | :--- |
|
|
131
|
+
| `api-key` | **Yes** | — | AI provider API key (pass via `${{ secrets.GEMINI_API_KEY }}`) |
|
|
132
|
+
| `provider` | No | `gemini` | `gemini`, `anthropic`, `openai`, `deepseek` |
|
|
133
|
+
| `model` | No | Auto | Specific model override (e.g. `gemini-3-flash-preview`, `claude-3-5-sonnet`) |
|
|
134
|
+
| `issue` | No | Auto | Bug description or instruction to heal |
|
|
135
|
+
| `test-command` | No | Auto | Custom test command override (e.g. `pytest tests/test_core.py`) |
|
|
136
|
+
| `max-attempts` | No | `4` | Maximum healing iterations before stopping |
|
|
137
|
+
|
|
86
138
|
### 2. Set Your Preferred API Key
|
|
87
139
|
|
|
88
140
|
Choose any provider:
|
|
@@ -145,6 +197,12 @@ patch-pilot/
|
|
|
145
197
|
└── pyproject.toml # Packaging and entry points
|
|
146
198
|
```
|
|
147
199
|
|
|
200
|
+
## 🌟 Support Open Source & Community Recognition
|
|
201
|
+
|
|
202
|
+
If **Patch Pilot** helped you heal broken tests or saved your team debugging time:
|
|
203
|
+
- ⭐ **Star this repository** to help other developers find it.
|
|
204
|
+
- 🚀 **[Nominate the author for the GitHub Stars Program](https://stars.github.com/nominate)** — your nomination takes 60 seconds and directly powers ongoing open-source tooling.
|
|
205
|
+
|
|
148
206
|
## 📄 License
|
|
149
207
|
|
|
150
208
|
MIT License. Copyright (c) 2026 Shubhransh Gupta.
|
|
@@ -31,7 +31,7 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
31
31
|
## 🌟 Key Capabilities
|
|
32
32
|
|
|
33
33
|
- **Multi-Model Intelligence**: Fix code using Claude 3.5 Sonnet, GPT-4o, Gemini 2.5, DeepSeek-Coder, or local Ollama.
|
|
34
|
-
- **Automatic Test Runner Detection**: Supports `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
34
|
+
- **Automatic Test Runner Detection**: Supports `swift test` (SPM), `xcodebuild` (iOS/macOS), `fastlane test`, `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
35
35
|
- **Iterative Self-Healing Loop**: If a patch fails the test suite, Patch Pilot captures the exact error tracebacks and re-prompts the model to refine the fix.
|
|
36
36
|
- **Git Branch & Commit Automation**: Automatically isolates changes in a dedicated Git feature branch and writes conventional commit messages upon test verification.
|
|
37
37
|
|
|
@@ -39,25 +39,77 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
39
39
|
|
|
40
40
|
### 1. Installation
|
|
41
41
|
|
|
42
|
+
Install directly from PyPI:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install patch-pilot-ai
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or install from source:
|
|
49
|
+
|
|
42
50
|
```bash
|
|
43
51
|
git clone https://github.com/shubhransh-gupta/patch-pilot.git
|
|
44
52
|
cd patch-pilot
|
|
45
53
|
pip install -e .
|
|
46
54
|
```
|
|
47
55
|
|
|
48
|
-
|
|
56
|
+
## 🔄 How to Use in Any Other Project (GitHub Action CI/CD)
|
|
57
|
+
|
|
58
|
+
You can drop **Patch Pilot** directly into **any repository's CI pipeline** to automatically diagnose failing tests and self-heal your code.
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
Available on the **GitHub Marketplace**: [`shubhransh-gupta/patch-pilot@v1`](https://github.com/shubhransh-gupta/patch-pilot)
|
|
61
|
+
|
|
62
|
+
### 1. Configure Your AI Provider Secret
|
|
63
|
+
In your target repository:
|
|
64
|
+
1. Navigate to **Settings** → **Secrets and variables** → **Actions** → **New repository secret**.
|
|
65
|
+
2. Name the secret `GEMINI_API_KEY` (or `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `DEEPSEEK_API_KEY`) and paste your API key.
|
|
66
|
+
|
|
67
|
+
### 2. Create the Workflow File
|
|
68
|
+
Add a new workflow file at `.github/workflows/self-heal-ci.yml`:
|
|
51
69
|
|
|
52
70
|
```yaml
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
name: Patch Pilot Self-Healing CI
|
|
72
|
+
|
|
73
|
+
on:
|
|
74
|
+
workflow_dispatch:
|
|
75
|
+
issue_comment:
|
|
76
|
+
types: [created]
|
|
77
|
+
|
|
78
|
+
jobs:
|
|
79
|
+
heal:
|
|
80
|
+
# Triggers manually or when a PR comment contains '/heal'
|
|
81
|
+
if: contains(github.event.comment.body, '/heal') || github.event_name == 'workflow_dispatch'
|
|
82
|
+
runs-on: ubuntu-latest
|
|
83
|
+
permissions:
|
|
84
|
+
contents: write
|
|
85
|
+
pull-requests: write
|
|
86
|
+
|
|
87
|
+
steps:
|
|
88
|
+
- name: Checkout Code
|
|
89
|
+
uses: actions/checkout@v4
|
|
90
|
+
with:
|
|
91
|
+
fetch-depth: 0
|
|
92
|
+
|
|
93
|
+
- name: Run Patch Pilot Self-Healing
|
|
94
|
+
uses: shubhransh-gupta/patch-pilot@v1
|
|
95
|
+
with:
|
|
96
|
+
api-key: ${{ secrets.GEMINI_API_KEY }}
|
|
97
|
+
provider: 'gemini'
|
|
98
|
+
issue: 'Fix failing unit tests in test suite'
|
|
99
|
+
max-attempts: '4'
|
|
59
100
|
```
|
|
60
101
|
|
|
102
|
+
### Action Inputs Reference
|
|
103
|
+
|
|
104
|
+
| Input | Required | Default | Description |
|
|
105
|
+
| :--- | :--- | :--- | :--- |
|
|
106
|
+
| `api-key` | **Yes** | — | AI provider API key (pass via `${{ secrets.GEMINI_API_KEY }}`) |
|
|
107
|
+
| `provider` | No | `gemini` | `gemini`, `anthropic`, `openai`, `deepseek` |
|
|
108
|
+
| `model` | No | Auto | Specific model override (e.g. `gemini-3-flash-preview`, `claude-3-5-sonnet`) |
|
|
109
|
+
| `issue` | No | Auto | Bug description or instruction to heal |
|
|
110
|
+
| `test-command` | No | Auto | Custom test command override (e.g. `pytest tests/test_core.py`) |
|
|
111
|
+
| `max-attempts` | No | `4` | Maximum healing iterations before stopping |
|
|
112
|
+
|
|
61
113
|
### 2. Set Your Preferred API Key
|
|
62
114
|
|
|
63
115
|
Choose any provider:
|
|
@@ -120,6 +172,12 @@ patch-pilot/
|
|
|
120
172
|
└── pyproject.toml # Packaging and entry points
|
|
121
173
|
```
|
|
122
174
|
|
|
175
|
+
## 🌟 Support Open Source & Community Recognition
|
|
176
|
+
|
|
177
|
+
If **Patch Pilot** helped you heal broken tests or saved your team debugging time:
|
|
178
|
+
- ⭐ **Star this repository** to help other developers find it.
|
|
179
|
+
- 🚀 **[Nominate the author for the GitHub Stars Program](https://stars.github.com/nominate)** — your nomination takes 60 seconds and directly powers ongoing open-source tooling.
|
|
180
|
+
|
|
123
181
|
## 📄 License
|
|
124
182
|
|
|
125
183
|
MIT License. Copyright (c) 2026 Shubhransh Gupta.
|
|
@@ -44,7 +44,10 @@ class PatchPilotAgent:
|
|
|
44
44
|
|
|
45
45
|
def _collect_repo_files(self) -> List[str]:
|
|
46
46
|
"""Lists files in the repository excluding common ignore paths."""
|
|
47
|
-
ignored = {
|
|
47
|
+
ignored = {
|
|
48
|
+
".git", ".venv", "venv", "node_modules", "__pycache__",
|
|
49
|
+
"dist", "build", ".build", "DerivedData", ".swiftpm", "Pods", "Carthage"
|
|
50
|
+
}
|
|
48
51
|
files = []
|
|
49
52
|
for root, dirs, filenames in os.walk(self.repo_dir):
|
|
50
53
|
dirs[:] = [d for d in dirs if d not in ignored]
|
|
@@ -73,6 +76,24 @@ class PatchPilotAgent:
|
|
|
73
76
|
test_cmd = self.runner.detect_test_command()
|
|
74
77
|
log(f"Target test command: `{test_cmd}`")
|
|
75
78
|
|
|
79
|
+
# Check initial tests: if already passing, no healing required
|
|
80
|
+
log(f"Executing initial test verification (`{test_cmd}`)...")
|
|
81
|
+
init_res = self.runner.run_tests(test_cmd)
|
|
82
|
+
if init_res.passed:
|
|
83
|
+
log("✅ All tests are already passing cleanly! No patching required.")
|
|
84
|
+
return {
|
|
85
|
+
"success": True,
|
|
86
|
+
"message": "All tests already passing cleanly.",
|
|
87
|
+
"branch": None,
|
|
88
|
+
"attempts": 0,
|
|
89
|
+
"patched_files": [],
|
|
90
|
+
"commit_message": "",
|
|
91
|
+
"diff": "",
|
|
92
|
+
"test_command": test_cmd,
|
|
93
|
+
}
|
|
94
|
+
log(f"Initial test failure confirmed (exit code {init_res.exit_code}).")
|
|
95
|
+
last_test_output = init_res.output_summary
|
|
96
|
+
|
|
76
97
|
# 3. Create branch if git repo
|
|
77
98
|
branch_name = None
|
|
78
99
|
if self.git.is_git_repo() and self.config.create_branch:
|
|
@@ -110,14 +131,16 @@ Return ONLY a JSON list of 1 to 3 relative file paths. Example:
|
|
|
110
131
|
if fp.is_file():
|
|
111
132
|
try:
|
|
112
133
|
with open(fp, "r", encoding="utf-8") as f:
|
|
113
|
-
|
|
134
|
+
c = f.read()
|
|
135
|
+
if len(c) > 15000:
|
|
136
|
+
c = c[:15000] + "\n...[truncated]..."
|
|
137
|
+
context_files[tf] = c
|
|
114
138
|
except Exception:
|
|
115
139
|
pass
|
|
116
140
|
|
|
117
141
|
# 5. Iterative Self-Healing Loop
|
|
118
142
|
attempt = 0
|
|
119
143
|
tests_passed = False
|
|
120
|
-
last_test_output = ""
|
|
121
144
|
patched_files = []
|
|
122
145
|
|
|
123
146
|
while attempt < self.config.max_healing_attempts and not tests_passed:
|
|
@@ -106,7 +106,7 @@ def main():
|
|
|
106
106
|
table.add_row("Git Branch", result["branch"])
|
|
107
107
|
if result.get("commit_message"):
|
|
108
108
|
table.add_row("Git Commit", result["commit_message"])
|
|
109
|
-
table.add_row("Test Suite", result
|
|
109
|
+
table.add_row("Test Suite", result.get("test_command", "Unknown"))
|
|
110
110
|
|
|
111
111
|
console.print("\n")
|
|
112
112
|
console.print(table)
|
|
@@ -4,6 +4,7 @@ Unified multi-provider LLM interface for Patch Pilot supporting Gemini, Claude,
|
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
import json
|
|
7
|
+
import time
|
|
7
8
|
import logging
|
|
8
9
|
from typing import Optional, Dict, Any, List
|
|
9
10
|
import requests
|
|
@@ -54,7 +55,7 @@ class UnifiedLLM:
|
|
|
54
55
|
|
|
55
56
|
# Check environment variable presence
|
|
56
57
|
if os.getenv("GEMINI_API_KEY"):
|
|
57
|
-
return "gemini", model or "gemini-
|
|
58
|
+
return "gemini", model or "gemini-3-flash-preview"
|
|
58
59
|
if os.getenv("OPENAI_API_KEY"):
|
|
59
60
|
return "openai", model or "gpt-4o"
|
|
60
61
|
if os.getenv("ANTHROPIC_API_KEY"):
|
|
@@ -64,7 +65,7 @@ class UnifiedLLM:
|
|
|
64
65
|
if os.getenv("DEEPSEEK_API_KEY"):
|
|
65
66
|
return "deepseek", model or "deepseek-chat"
|
|
66
67
|
|
|
67
|
-
return "gemini", model or "gemini-
|
|
68
|
+
return "gemini", model or "gemini-3-flash-preview"
|
|
68
69
|
|
|
69
70
|
def _default_model_for_provider(self, provider: str) -> str:
|
|
70
71
|
defaults = {
|
|
@@ -105,32 +106,43 @@ class UnifiedLLM:
|
|
|
105
106
|
return self._call_gemini(prompt, system_instruction)
|
|
106
107
|
|
|
107
108
|
def _call_gemini(self, prompt: str, system_instruction: Optional[str]) -> str:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
models_to_try = [
|
|
110
|
+
self.model,
|
|
111
|
+
"gemini-2.5-flash",
|
|
112
|
+
"gemini-2.5-pro",
|
|
113
|
+
"gemini-1.5-flash",
|
|
114
|
+
"gemini-3-flash-preview",
|
|
115
|
+
"gemini-flash-latest",
|
|
116
|
+
]
|
|
117
|
+
unique_models = [m for m in dict.fromkeys(models_to_try) if m]
|
|
118
|
+
|
|
119
|
+
request_timeout = max(self.timeout, 90)
|
|
120
|
+
last_error = None
|
|
121
|
+
for m in unique_models:
|
|
122
|
+
for retry in range(2):
|
|
123
|
+
try:
|
|
124
|
+
url = f"https://generativelanguage.googleapis.com/v1beta/models/{m}:generateContent?key={self.api_key}"
|
|
125
|
+
contents = []
|
|
126
|
+
if system_instruction:
|
|
127
|
+
contents.append({"role": "user", "parts": [{"text": f"SYSTEM: {system_instruction}"}]})
|
|
128
|
+
contents.append({"role": "user", "parts": [{"text": prompt}]})
|
|
129
|
+
resp = requests.post(url, json={"contents": contents}, timeout=request_timeout)
|
|
130
|
+
if resp.status_code == 200:
|
|
131
|
+
data = resp.json()
|
|
132
|
+
candidates = data.get("candidates", [])
|
|
133
|
+
if candidates and "content" in candidates[0]:
|
|
134
|
+
parts = candidates[0]["content"].get("parts", [])
|
|
135
|
+
if parts and "text" in parts[0]:
|
|
136
|
+
return parts[0]["text"]
|
|
137
|
+
elif resp.status_code in (503, 429):
|
|
138
|
+
time.sleep(2)
|
|
139
|
+
continue
|
|
140
|
+
last_error = f"{m} HTTP {resp.status_code}: {resp.text[:100]}"
|
|
141
|
+
break
|
|
142
|
+
except Exception as e:
|
|
143
|
+
last_error = e
|
|
144
|
+
|
|
145
|
+
raise RuntimeError(f"All Gemini models failed. Last error: {last_error}")
|
|
134
146
|
|
|
135
147
|
def _call_anthropic(self, prompt: str, system_instruction: Optional[str]) -> str:
|
|
136
148
|
url = "https://api.anthropic.com/v1/messages"
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Subprocess test runner and automatic framework detector.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
5
7
|
import subprocess
|
|
6
8
|
from pathlib import Path
|
|
7
9
|
from typing import Tuple, Optional
|
|
@@ -20,6 +22,7 @@ class TestResult:
|
|
|
20
22
|
|
|
21
23
|
class TestRunner:
|
|
22
24
|
"""Detects and runs project tests."""
|
|
25
|
+
__test__ = False
|
|
23
26
|
|
|
24
27
|
def __init__(self, repo_dir: Path, custom_cmd: Optional[str] = None, timeout: int = 45):
|
|
25
28
|
self.repo_dir = repo_dir
|
|
@@ -31,6 +34,27 @@ class TestRunner:
|
|
|
31
34
|
if self.custom_cmd:
|
|
32
35
|
return self.custom_cmd
|
|
33
36
|
|
|
37
|
+
# Swift / SPM
|
|
38
|
+
if (self.repo_dir / "Package.swift").is_file():
|
|
39
|
+
return "swift test"
|
|
40
|
+
|
|
41
|
+
# Fastlane
|
|
42
|
+
if (self.repo_dir / "fastlane" / "Fastfile").is_file() or (self.repo_dir / "Fastfile").is_file():
|
|
43
|
+
if (self.repo_dir / "Gemfile").is_file():
|
|
44
|
+
return "bundle exec fastlane test"
|
|
45
|
+
return "fastlane test"
|
|
46
|
+
|
|
47
|
+
# Xcode workspace / project
|
|
48
|
+
workspaces = sorted(self.repo_dir.glob("*.xcworkspace"))
|
|
49
|
+
if workspaces:
|
|
50
|
+
scheme = workspaces[0].stem
|
|
51
|
+
return f"xcodebuild test -workspace {workspaces[0].name} -scheme {scheme} -destination 'generic/platform=iOS Simulator'"
|
|
52
|
+
|
|
53
|
+
projects = sorted(self.repo_dir.glob("*.xcodeproj"))
|
|
54
|
+
if projects:
|
|
55
|
+
scheme = projects[0].stem
|
|
56
|
+
return f"xcodebuild test -project {projects[0].name} -scheme {scheme} -destination 'generic/platform=iOS Simulator'"
|
|
57
|
+
|
|
34
58
|
# Python
|
|
35
59
|
if (self.repo_dir / "pytest.ini").is_file() or (self.repo_dir / "pyproject.toml").is_file() or (self.repo_dir / "tests").is_dir():
|
|
36
60
|
return "pytest"
|
|
@@ -54,6 +78,11 @@ class TestRunner:
|
|
|
54
78
|
def run_tests(self, command: Optional[str] = None) -> TestResult:
|
|
55
79
|
"""Executes test suite and captures output."""
|
|
56
80
|
cmd_str = command or self.detect_test_command()
|
|
81
|
+
env = os.environ.copy()
|
|
82
|
+
py_bin_dir = str(Path(sys.executable).parent)
|
|
83
|
+
if py_bin_dir not in env.get("PATH", ""):
|
|
84
|
+
env["PATH"] = f"{py_bin_dir}:{env.get('PATH', '')}"
|
|
85
|
+
|
|
57
86
|
try:
|
|
58
87
|
res = subprocess.run(
|
|
59
88
|
cmd_str,
|
|
@@ -61,7 +90,8 @@ class TestRunner:
|
|
|
61
90
|
shell=True,
|
|
62
91
|
capture_output=True,
|
|
63
92
|
text=True,
|
|
64
|
-
timeout=self.timeout
|
|
93
|
+
timeout=self.timeout,
|
|
94
|
+
env=env
|
|
65
95
|
)
|
|
66
96
|
passed = (res.returncode == 0)
|
|
67
97
|
combined_output = (res.stdout + "\n" + res.stderr).strip()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patch-pilot-ai
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Autonomous code healing and bug patching agent powered by Google Gemini.
|
|
5
5
|
Author: Shubhransh Gupta
|
|
6
6
|
License: MIT
|
|
@@ -56,7 +56,7 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
56
56
|
## 🌟 Key Capabilities
|
|
57
57
|
|
|
58
58
|
- **Multi-Model Intelligence**: Fix code using Claude 3.5 Sonnet, GPT-4o, Gemini 2.5, DeepSeek-Coder, or local Ollama.
|
|
59
|
-
- **Automatic Test Runner Detection**: Supports `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
59
|
+
- **Automatic Test Runner Detection**: Supports `swift test` (SPM), `xcodebuild` (iOS/macOS), `fastlane test`, `pytest`, `unittest`, `npm test`, `cargo test`, and `go test` with zero configuration.
|
|
60
60
|
- **Iterative Self-Healing Loop**: If a patch fails the test suite, Patch Pilot captures the exact error tracebacks and re-prompts the model to refine the fix.
|
|
61
61
|
- **Git Branch & Commit Automation**: Automatically isolates changes in a dedicated Git feature branch and writes conventional commit messages upon test verification.
|
|
62
62
|
|
|
@@ -64,25 +64,77 @@ Patch Pilot works with all major AI providers or entirely local setups:
|
|
|
64
64
|
|
|
65
65
|
### 1. Installation
|
|
66
66
|
|
|
67
|
+
Install directly from PyPI:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install patch-pilot-ai
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or install from source:
|
|
74
|
+
|
|
67
75
|
```bash
|
|
68
76
|
git clone https://github.com/shubhransh-gupta/patch-pilot.git
|
|
69
77
|
cd patch-pilot
|
|
70
78
|
pip install -e .
|
|
71
79
|
```
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
## 🔄 How to Use in Any Other Project (GitHub Action CI/CD)
|
|
82
|
+
|
|
83
|
+
You can drop **Patch Pilot** directly into **any repository's CI pipeline** to automatically diagnose failing tests and self-heal your code.
|
|
74
84
|
|
|
75
|
-
|
|
85
|
+
Available on the **GitHub Marketplace**: [`shubhransh-gupta/patch-pilot@v1`](https://github.com/shubhransh-gupta/patch-pilot)
|
|
86
|
+
|
|
87
|
+
### 1. Configure Your AI Provider Secret
|
|
88
|
+
In your target repository:
|
|
89
|
+
1. Navigate to **Settings** → **Secrets and variables** → **Actions** → **New repository secret**.
|
|
90
|
+
2. Name the secret `GEMINI_API_KEY` (or `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `DEEPSEEK_API_KEY`) and paste your API key.
|
|
91
|
+
|
|
92
|
+
### 2. Create the Workflow File
|
|
93
|
+
Add a new workflow file at `.github/workflows/self-heal-ci.yml`:
|
|
76
94
|
|
|
77
95
|
```yaml
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
name: Patch Pilot Self-Healing CI
|
|
97
|
+
|
|
98
|
+
on:
|
|
99
|
+
workflow_dispatch:
|
|
100
|
+
issue_comment:
|
|
101
|
+
types: [created]
|
|
102
|
+
|
|
103
|
+
jobs:
|
|
104
|
+
heal:
|
|
105
|
+
# Triggers manually or when a PR comment contains '/heal'
|
|
106
|
+
if: contains(github.event.comment.body, '/heal') || github.event_name == 'workflow_dispatch'
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
permissions:
|
|
109
|
+
contents: write
|
|
110
|
+
pull-requests: write
|
|
111
|
+
|
|
112
|
+
steps:
|
|
113
|
+
- name: Checkout Code
|
|
114
|
+
uses: actions/checkout@v4
|
|
115
|
+
with:
|
|
116
|
+
fetch-depth: 0
|
|
117
|
+
|
|
118
|
+
- name: Run Patch Pilot Self-Healing
|
|
119
|
+
uses: shubhransh-gupta/patch-pilot@v1
|
|
120
|
+
with:
|
|
121
|
+
api-key: ${{ secrets.GEMINI_API_KEY }}
|
|
122
|
+
provider: 'gemini'
|
|
123
|
+
issue: 'Fix failing unit tests in test suite'
|
|
124
|
+
max-attempts: '4'
|
|
84
125
|
```
|
|
85
126
|
|
|
127
|
+
### Action Inputs Reference
|
|
128
|
+
|
|
129
|
+
| Input | Required | Default | Description |
|
|
130
|
+
| :--- | :--- | :--- | :--- |
|
|
131
|
+
| `api-key` | **Yes** | — | AI provider API key (pass via `${{ secrets.GEMINI_API_KEY }}`) |
|
|
132
|
+
| `provider` | No | `gemini` | `gemini`, `anthropic`, `openai`, `deepseek` |
|
|
133
|
+
| `model` | No | Auto | Specific model override (e.g. `gemini-3-flash-preview`, `claude-3-5-sonnet`) |
|
|
134
|
+
| `issue` | No | Auto | Bug description or instruction to heal |
|
|
135
|
+
| `test-command` | No | Auto | Custom test command override (e.g. `pytest tests/test_core.py`) |
|
|
136
|
+
| `max-attempts` | No | `4` | Maximum healing iterations before stopping |
|
|
137
|
+
|
|
86
138
|
### 2. Set Your Preferred API Key
|
|
87
139
|
|
|
88
140
|
Choose any provider:
|
|
@@ -145,6 +197,12 @@ patch-pilot/
|
|
|
145
197
|
└── pyproject.toml # Packaging and entry points
|
|
146
198
|
```
|
|
147
199
|
|
|
200
|
+
## 🌟 Support Open Source & Community Recognition
|
|
201
|
+
|
|
202
|
+
If **Patch Pilot** helped you heal broken tests or saved your team debugging time:
|
|
203
|
+
- ⭐ **Star this repository** to help other developers find it.
|
|
204
|
+
- 🚀 **[Nominate the author for the GitHub Stars Program](https://stars.github.com/nominate)** — your nomination takes 60 seconds and directly powers ongoing open-source tooling.
|
|
205
|
+
|
|
148
206
|
## 📄 License
|
|
149
207
|
|
|
150
208
|
MIT License. Copyright (c) 2026 Shubhransh Gupta.
|
|
@@ -12,4 +12,5 @@ patch_pilot_ai.egg-info/SOURCES.txt
|
|
|
12
12
|
patch_pilot_ai.egg-info/dependency_links.txt
|
|
13
13
|
patch_pilot_ai.egg-info/entry_points.txt
|
|
14
14
|
patch_pilot_ai.egg-info/requires.txt
|
|
15
|
-
patch_pilot_ai.egg-info/top_level.txt
|
|
15
|
+
patch_pilot_ai.egg-info/top_level.txt
|
|
16
|
+
tests/test_pilot.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "patch-pilot-ai"
|
|
7
|
-
version = "
|
|
7
|
+
version = "1.1.0"
|
|
8
8
|
description = "Autonomous code healing and bug patching agent powered by Google Gemini."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Shubhransh Gupta" }]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from patch_pilot.config import PatchConfig
|
|
3
|
+
from patch_pilot.runner import TestRunner
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_config_defaults():
|
|
7
|
+
cfg = PatchConfig()
|
|
8
|
+
assert cfg.provider in ("gemini", "openai", "anthropic", None)
|
|
9
|
+
assert cfg.max_healing_attempts > 0
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_runner_detection(tmp_path):
|
|
13
|
+
runner = TestRunner(repo_dir=tmp_path)
|
|
14
|
+
assert runner.detect_test_command() == "pytest"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|