Spaces:
Sleeping
Sleeping
Deploy code agent from GitHub Actions
Browse files
app.py
CHANGED
|
@@ -98,6 +98,121 @@ def is_successful_execution(request: CodeRepairRequest):
|
|
| 98 |
return False
|
| 99 |
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def get_successful_execution_guidance(request: CodeRepairRequest):
|
| 102 |
if not is_successful_execution(request):
|
| 103 |
return None
|
|
@@ -254,6 +369,7 @@ Return only these sections:
|
|
| 254 |
If execution success is true or exit code is 0, do not say the project failed.
|
| 255 |
If tests passed and only warnings exist, say no blocking application source code change is required.
|
| 256 |
If the failure is Maven not available or Maven Wrapper missing, clearly say no application source code change is required.
|
|
|
|
| 257 |
Do not include system/user/assistant labels.
|
| 258 |
Do not repeat the prompt.
|
| 259 |
Do not invent files that are not shown.
|
|
@@ -315,6 +431,11 @@ def fallback_code_guidance(request: CodeRepairRequest):
|
|
| 315 |
if successful_guidance:
|
| 316 |
return successful_guidance
|
| 317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
if request.error_log:
|
| 319 |
summary = (
|
| 320 |
"A code-level issue may exist based on the provided error log. "
|
|
@@ -429,6 +550,11 @@ def suggest_code_fix(request: CodeRepairRequest):
|
|
| 429 |
if successful_guidance:
|
| 430 |
return successful_guidance
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
fallback_result = fallback_code_guidance(request)
|
| 433 |
|
| 434 |
try:
|
|
|
|
| 98 |
return False
|
| 99 |
|
| 100 |
|
| 101 |
+
def extract_compile_error_details(request: CodeRepairRequest):
|
| 102 |
+
logs = request.error_log or ""
|
| 103 |
+
|
| 104 |
+
if "cannot find symbol" not in logs.lower():
|
| 105 |
+
return None
|
| 106 |
+
|
| 107 |
+
file_match = re.search(
|
| 108 |
+
r"([A-Za-z]:[/\\].*?\.java):\[(\d+),(\d+)\]",
|
| 109 |
+
logs
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
symbol_match = re.search(
|
| 113 |
+
r"symbol:\s+class\s+([A-Za-z_][A-Za-z0-9_]*)",
|
| 114 |
+
logs,
|
| 115 |
+
re.IGNORECASE
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
location_match = re.search(
|
| 119 |
+
r"location:\s+class\s+([A-Za-z0-9_.$]+)",
|
| 120 |
+
logs,
|
| 121 |
+
re.IGNORECASE
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
missing_symbol = symbol_match.group(1) if symbol_match else None
|
| 125 |
+
location_class = location_match.group(1) if location_match else None
|
| 126 |
+
|
| 127 |
+
line_number = file_match.group(2) if file_match else None
|
| 128 |
+
column_number = file_match.group(3) if file_match else None
|
| 129 |
+
file_path = file_match.group(1) if file_match else request.file_path
|
| 130 |
+
|
| 131 |
+
return {
|
| 132 |
+
"error_type": "cannot-find-symbol",
|
| 133 |
+
"file_path": file_path,
|
| 134 |
+
"line_number": line_number,
|
| 135 |
+
"column_number": column_number,
|
| 136 |
+
"missing_symbol": missing_symbol,
|
| 137 |
+
"location_class": location_class,
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def get_compile_error_guidance(request: CodeRepairRequest):
|
| 142 |
+
details = extract_compile_error_details(request)
|
| 143 |
+
|
| 144 |
+
if not details:
|
| 145 |
+
return None
|
| 146 |
+
|
| 147 |
+
code = request.code_snippet or ""
|
| 148 |
+
missing_symbol = details.get("missing_symbol")
|
| 149 |
+
location_class = details.get("location_class") or ""
|
| 150 |
+
short_location_class = location_class.split(".")[-1] if location_class else None
|
| 151 |
+
|
| 152 |
+
if (
|
| 153 |
+
missing_symbol
|
| 154 |
+
and short_location_class
|
| 155 |
+
and missing_symbol in code
|
| 156 |
+
and f"{missing_symbol}.class" in code
|
| 157 |
+
and f"{short_location_class}.class" not in code
|
| 158 |
+
):
|
| 159 |
+
summary = (
|
| 160 |
+
f"Problem: The Maven compile step failed because `{missing_symbol}` cannot be found. "
|
| 161 |
+
f"In `{request.file_path}`, the code references `{missing_symbol}.class`, but the current application class is `{short_location_class}`.\n\n"
|
| 162 |
+
f"Safe fix approach: Replace the incorrect class reference with the existing application class. This is a targeted compile fix for the detected line.\n\n"
|
| 163 |
+
f"Suggested code change: Change `SpringApplication.run({missing_symbol}.class, args);` to "
|
| 164 |
+
f"`SpringApplication.run({short_location_class}.class, args);`.\n\n"
|
| 165 |
+
"Verification step: Rerun `mvnw.cmd test` or Stitch QA and confirm the compilation error is gone."
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
return {
|
| 169 |
+
"agent": "code-agent",
|
| 170 |
+
"mode": "rule-based",
|
| 171 |
+
"summary": summary,
|
| 172 |
+
"risk_level": "MEDIUM",
|
| 173 |
+
"auto_apply": False,
|
| 174 |
+
"suggested_patch": (
|
| 175 |
+
f"Replace `{missing_symbol}.class` with `{short_location_class}.class` in `{request.file_path}`."
|
| 176 |
+
),
|
| 177 |
+
"verification": "Rerun Stitch QA and confirm the Maven compile phase succeeds."
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
if missing_symbol:
|
| 181 |
+
summary = (
|
| 182 |
+
f"Problem: The Maven compile step failed because the symbol `{missing_symbol}` could not be found.\n\n"
|
| 183 |
+
"Safe fix approach: Check whether the symbol name is misspelled, whether the class exists, or whether the required import/dependency is missing.\n\n"
|
| 184 |
+
f"Suggested code change: Fix the reference to `{missing_symbol}` by using the correct existing class name, adding the missing import, or adding the required dependency.\n\n"
|
| 185 |
+
"Verification step: Rerun the Maven test command and confirm the compile error is resolved."
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
return {
|
| 189 |
+
"agent": "code-agent",
|
| 190 |
+
"mode": "rule-based",
|
| 191 |
+
"summary": summary,
|
| 192 |
+
"risk_level": "MEDIUM",
|
| 193 |
+
"auto_apply": False,
|
| 194 |
+
"suggested_patch": None,
|
| 195 |
+
"verification": "Rerun Stitch QA after applying the targeted compile fix."
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
summary = (
|
| 199 |
+
"Problem: The Maven compile step failed with a cannot-find-symbol error.\n\n"
|
| 200 |
+
"Safe fix approach: Inspect the compiler error location, identify the missing class, method, or variable, and apply the smallest targeted fix.\n\n"
|
| 201 |
+
"Suggested code change: Correct the missing or invalid symbol reference in the affected Java file.\n\n"
|
| 202 |
+
"Verification step: Rerun the Maven test command and confirm compilation succeeds."
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
return {
|
| 206 |
+
"agent": "code-agent",
|
| 207 |
+
"mode": "rule-based",
|
| 208 |
+
"summary": summary,
|
| 209 |
+
"risk_level": "MEDIUM",
|
| 210 |
+
"auto_apply": False,
|
| 211 |
+
"suggested_patch": None,
|
| 212 |
+
"verification": "Rerun Stitch QA after fixing the cannot-find-symbol error."
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
|
| 216 |
def get_successful_execution_guidance(request: CodeRepairRequest):
|
| 217 |
if not is_successful_execution(request):
|
| 218 |
return None
|
|
|
|
| 369 |
If execution success is true or exit code is 0, do not say the project failed.
|
| 370 |
If tests passed and only warnings exist, say no blocking application source code change is required.
|
| 371 |
If the failure is Maven not available or Maven Wrapper missing, clearly say no application source code change is required.
|
| 372 |
+
If the error says cannot find symbol, identify the missing symbol and suggest the smallest targeted fix.
|
| 373 |
Do not include system/user/assistant labels.
|
| 374 |
Do not repeat the prompt.
|
| 375 |
Do not invent files that are not shown.
|
|
|
|
| 431 |
if successful_guidance:
|
| 432 |
return successful_guidance
|
| 433 |
|
| 434 |
+
compile_error_guidance = get_compile_error_guidance(request)
|
| 435 |
+
|
| 436 |
+
if compile_error_guidance:
|
| 437 |
+
return compile_error_guidance
|
| 438 |
+
|
| 439 |
if request.error_log:
|
| 440 |
summary = (
|
| 441 |
"A code-level issue may exist based on the provided error log. "
|
|
|
|
| 550 |
if successful_guidance:
|
| 551 |
return successful_guidance
|
| 552 |
|
| 553 |
+
compile_error_guidance = get_compile_error_guidance(request)
|
| 554 |
+
|
| 555 |
+
if compile_error_guidance:
|
| 556 |
+
return compile_error_guidance
|
| 557 |
+
|
| 558 |
fallback_result = fallback_code_guidance(request)
|
| 559 |
|
| 560 |
try:
|