archiving tracks

This commit is contained in:
2026-03-08 13:29:53 -04:00
parent b44c0f42cd
commit 66338b3ba0
83 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# Advanced Tier 4 QA Auto-Patching
**Track ID:** tier4_auto_patching_20260306
**Status:** Planned
**See Also:**
- [Spec](./spec.md)
- [Plan](./plan.md)

View File

@@ -0,0 +1,9 @@
{
"id": "tier4_auto_patching_20260306",
"name": "Advanced Tier 4 QA Auto-Patching",
"status": "planned",
"created_at": "2026-03-06T00:00:00Z",
"updated_at": "2026-03-06T00:00:00Z",
"type": "feature",
"priority": "medium"
}

View File

@@ -0,0 +1,123 @@
# Implementation Plan: Tier 4 Auto-Patching (tier4_auto_patching_20260306)
> **Reference:** [Spec](./spec.md) | [Architecture Guide](../../../docs/guide_architecture.md)
## Phase 1: Patch Generation
Focus: Generate unified diff on test failure
- [x] Task 1.1: Initialize MMA Environment
- [x] Task 1.2: Extend Tier 4 prompt for patch generation
- WHERE: `src/mma_prompts.py` or inline in `ai_client.py`
- WHAT: Prompt to generate unified diff
- HOW:
```python
TIER4_PATCH_PROMPT = """
Analyze the error and generate a unified diff patch to fix it.
Output format:
--- a/path/to/file.py
+++ b/path/to/file.py
@@ -line,count +line,count @@
context
-removed line
+added line
context
"""
```
- [x] Task 1.3: Add patch generation function
- WHERE: `src/ai_client.py`
- WHAT: Generate patch from error
- HOW:
```python
def run_tier4_patch_generation(error: str, file_context: str) -> str:
prompt = TIER4_PATCH_PROMPT + f"\n\nError:\n{error}\n\nFiles:\n{file_context}"
return send(prompt, model="gemini-2.5-flash-lite")
```
## Phase 2: Diff Viewer UI
Focus: Display side-by-side diff
- [x] Task 2.1: Parse unified diff
- WHERE: `src/gui_2.py` or new `src/diff_viewer.py`
- WHAT: Parse diff into hunks
- HOW:
```python
def parse_diff(diff_text: str) -> list[dict]:
hunks = []
current_hunk = None
for line in diff_text.split("\n"):
if line.startswith("@@"):
if current_hunk: hunks.append(current_hunk)
current_hunk = {"header": line, "lines": []}
elif current_hunk:
current_hunk["lines"].append(line)
if current_hunk: hunks.append(current_hunk)
return hunks
```
- [x] Task 2.2: Render diff viewer
- WHERE: `src/gui_2.py`
- WHAT: Color-coded diff display
- HOW:
```python
for hunk in hunks:
for line in hunk["lines"]:
if line.startswith("+"):
imgui.text_colored(vec4(100, 255, 100, 255), line)
elif line.startswith("-"):
imgui.text_colored(vec4(255, 100, 100, 255), line)
else:
imgui.text(line)
```
## Phase 3: Patch Application
Focus: Apply patch with backup
- [x] Task 3.1: Create backup before apply
- WHERE: `src/gui_2.py` or `src/mcp_client.py`
- WHAT: Backup file to .backup
- HOW:
```python
import shutil
backup_path = file_path.with_suffix(file_path.suffix + ".backup")
shutil.copy(file_path, backup_path)
```
- [x] Task 3.2: Apply patch
- WHERE: `src/gui_2.py`
- WHAT: Use patch command or difflib
- HOW:
```python
import subprocess
result = subprocess.run(["patch", "-p1"], input=diff_text, capture_output=True, text=True)
```
- [x] Task 3.3: Restore on failure
- WHERE: `src/gui_2.py`
- WHAT: Restore from backup if patch fails
- HOW: `shutil.copy(backup_path, file_path)`
## Phase 4: Modal UI
Focus: Approval modal for patches
- [x] Task 4.1: Create patch approval modal
- WHERE: `src/gui_2.py`
- WHAT: Modal with diff preview and Apply/Reject buttons
- HOW:
```python
if self._show_patch_modal:
imgui.open_popup("Apply Patch?")
if imgui.begin_popup_modal("Apply Patch?"):
# Render diff
if imgui.button("Apply"):
self._apply_current_patch()
imgui.close_current_popup()
imgui.same_line()
if imgui.button("Reject"):
imgui.close_current_popup()
imgui.end_popup()
```
## Phase 5: Testing
- [x] Task 5.1: Write unit tests
- [x] Task 5.2: Conductor - Phase Verification

View File

@@ -0,0 +1,142 @@
# Track Specification: Advanced Tier 4 QA Auto-Patching (tier4_auto_patching_20260306)
## Overview
Elevate Tier 4 from log summarizer to auto-patcher. When verification tests fail, Tier 4 generates a unified diff patch. GUI displays side-by-side diff; user clicks Apply Patch to resume pipeline.
## Current State Audit
### Already Implemented (DO NOT re-implement)
#### Tier 4 Analysis (ai_client.py)
- **`run_tier4_analysis(stderr: str) -> str`**: Analyzes error, returns summary
- **Prompt**: Uses `mma_prompts.PROMPTS["tier4_error_triage"]`
- **Output**: Text analysis, no code generation
#### Error Interception (shell_runner.py)
- **`run_powershell()`**: Accepts `qa_callback` parameter
- **On failure**: Calls `qa_callback(stderr)` and appends to output
- **Integrated**: `ai_client._run_script()` passes `qa_callback`
#### MCP Tools (mcp_client.py)
- **`set_file_slice()`**: Replace line range in file
- **`py_update_definition()`**: Replace class/function via AST
- **`edit_file()`**: String replacement in file
- **No diff generation or patch application**
### Gaps to Fill (This Track's Scope)
- Tier 4 doesn't generate patches
- No diff visualization in GUI
- No patch application mechanism
- No rollback capability
## Architectural Constraints
### Safe Preview
- Patches MUST be previewed before application
- User MUST see exactly what will change
- No automatic application without approval
### Atomic Application
- Patch applies all changes or none
- If partial application fails, rollback
### Rollback Support
- Backup created before patch
- User can undo applied patch
- Backup stored temporarily
## Architecture Reference
### Key Integration Points
| File | Lines | Purpose |
|------|-------|---------|
| `src/ai_client.py` | ~700-750 | `run_tier4_analysis()` |
| `src/shell_runner.py` | 50-100 | `run_powershell()` with qa_callback |
| `src/mcp_client.py` | 300-350 | `set_file_slice()`, `edit_file()` |
| `src/gui_2.py` | 2400-2500 | Confirmation dialogs pattern |
### Proposed Patch Workflow
```
1. Test fails → stderr captured
2. Tier 4 analyzes → generates unified diff
3. GUI shows diff viewer with Apply/Reject buttons
4. User clicks Apply:
a. Backup original file(s)
b. Apply patch via subprocess or difflib
c. Verify patch applied cleanly
d. If fails, restore from backup
5. Pipeline resumes with patched code
```
### Unified Diff Format
```diff
--- a/src/target_file.py
+++ b/src/target_file.py
@@ -10,5 +10,6 @@
def existing_function():
- old_line
+ new_line
+ additional_line
```
## Functional Requirements
### FR1: Patch Generation
- Tier 4 prompt enhanced to generate unified diff
- Output format: standard `diff -u` format
- Include file path in diff header
- Multiple files supported
### FR2: Diff Viewer GUI
- Side-by-side or unified view
- Color-coded additions (green) and deletions (red)
- Line numbers visible
- Scrollable for large diffs
### FR3: Apply Button
- Creates backup: `file.py.backup`
- Applies patch: `patch -p1 < diff.patch` or Python difflib
- Verifies success
- Shows confirmation or error
### FR4: Rollback
- Restore from backup if patch fails
- Manual rollback button after successful patch
- Backup deleted after explicit user action
## Non-Functional Requirements
| Requirement | Constraint |
|-------------|------------|
| Patch Generation | <5s for typical errors |
| Diff Rendering | <100ms for 100-line diff |
| Backup Storage | Temp dir, cleaned on exit |
## Testing Requirements
### Unit Tests
- Test diff generation format
- Test patch application logic
- Test backup/rollback
### Integration Tests (via `live_gui` fixture)
- Trigger test failure, verify patch generated
- Apply patch, verify file changed correctly
- Rollback, verify file restored
## Out of Scope
- Automatic patch application (always requires approval)
- Patch conflict resolution (reject if conflict)
- Multi-file patch coordination
## Acceptance Criteria
- [ ] Tier 4 generates valid unified diff on test failure
- [ ] GUI displays readable side-by-side diff
- [ ] User can approve/reject patch
- [ ] Approved patches applied correctly
- [ ] Rollback available on failure
- [ ] Backup files cleaned up
- [ ] 1-space indentation maintained