Spaces:
Running
Running
zhimin-z commited on
Commit ·
d8a02a1
1
Parent(s): a6f4938
add
Browse files- app.py +13 -8
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -9,8 +9,10 @@ import gitlab
|
|
| 9 |
import httpx
|
| 10 |
import io
|
| 11 |
import json
|
|
|
|
| 12 |
import os
|
| 13 |
import random
|
|
|
|
| 14 |
import shutil
|
| 15 |
import socket
|
| 16 |
import subprocess
|
|
@@ -1052,7 +1054,6 @@ def detect_folder_violation_error(error_message, agent_dir):
|
|
| 1052 |
|
| 1053 |
if has_violation_pattern:
|
| 1054 |
# Look for absolute path references that are outside the agent directory
|
| 1055 |
-
import re
|
| 1056 |
absolute_paths = re.findall(r'[/\\][a-zA-Z0-9_/\\.-]+', error_message)
|
| 1057 |
for path in absolute_paths:
|
| 1058 |
if agent_dir not in path and not path.startswith('./') and not path.startswith('../'):
|
|
@@ -1099,7 +1100,6 @@ def analyze_agent_output_for_violations(output, error, agent_dir):
|
|
| 1099 |
|
| 1100 |
# Also check for absolute path usage in output
|
| 1101 |
if any(indicator in output_str for indicator in violation_indicators):
|
| 1102 |
-
import re
|
| 1103 |
absolute_paths = re.findall(r'[/\\][a-zA-Z0-9_/\\.-]+', output)
|
| 1104 |
for path in absolute_paths:
|
| 1105 |
if agent_dir not in path:
|
|
@@ -1589,32 +1589,37 @@ def format_all_rounds(rounds):
|
|
| 1589 |
agent produced file changes — the cumulative git diff up to that
|
| 1590 |
round. Rendering the diff per-round (rather than once at the end)
|
| 1591 |
means successive responses always re-check and refresh the diff.
|
|
|
|
| 1592 |
"""
|
| 1593 |
SEPARATOR = (
|
| 1594 |
"<div style='text-align: center; color: #888888; margin: 16px 0; "
|
| 1595 |
"border-top: 1px solid #dddddd; padding-top: 10px;'>"
|
| 1596 |
-
"<em>
|
| 1597 |
)
|
| 1598 |
formatted = ""
|
| 1599 |
for i, r in enumerate(rounds):
|
| 1600 |
prompt = strip_context(r["prompt"]) if i == 0 else r["prompt"]
|
|
|
|
|
|
|
| 1601 |
if i > 0:
|
| 1602 |
formatted += SEPARATOR
|
| 1603 |
formatted += (
|
| 1604 |
f"<div style='color: #0066cc; background-color: #f0f7ff; "
|
| 1605 |
f"padding: 10px; border-radius: 5px; margin-bottom: 10px;'>"
|
| 1606 |
-
f"<strong>User:</strong> {
|
| 1607 |
)
|
| 1608 |
formatted += (
|
| 1609 |
f"<div style='color: #006633; background-color: #f0fff0; "
|
| 1610 |
f"padding: 10px; border-radius: 5px; margin-bottom: 10px;'>"
|
| 1611 |
-
f"<strong>Model:</strong> {
|
| 1612 |
)
|
| 1613 |
if r.get("diff"):
|
| 1614 |
-
|
| 1615 |
-
f"
|
| 1616 |
-
f"```diff\n{r['diff']}\n```
|
|
|
|
| 1617 |
)
|
|
|
|
| 1618 |
return formatted
|
| 1619 |
|
| 1620 |
|
|
|
|
| 9 |
import httpx
|
| 10 |
import io
|
| 11 |
import json
|
| 12 |
+
import markdown as md_lib
|
| 13 |
import os
|
| 14 |
import random
|
| 15 |
+
import re
|
| 16 |
import shutil
|
| 17 |
import socket
|
| 18 |
import subprocess
|
|
|
|
| 1054 |
|
| 1055 |
if has_violation_pattern:
|
| 1056 |
# Look for absolute path references that are outside the agent directory
|
|
|
|
| 1057 |
absolute_paths = re.findall(r'[/\\][a-zA-Z0-9_/\\.-]+', error_message)
|
| 1058 |
for path in absolute_paths:
|
| 1059 |
if agent_dir not in path and not path.startswith('./') and not path.startswith('../'):
|
|
|
|
| 1100 |
|
| 1101 |
# Also check for absolute path usage in output
|
| 1102 |
if any(indicator in output_str for indicator in violation_indicators):
|
|
|
|
| 1103 |
absolute_paths = re.findall(r'[/\\][a-zA-Z0-9_/\\.-]+', output)
|
| 1104 |
for path in absolute_paths:
|
| 1105 |
if agent_dir not in path:
|
|
|
|
| 1589 |
agent produced file changes — the cumulative git diff up to that
|
| 1590 |
round. Rendering the diff per-round (rather than once at the end)
|
| 1591 |
means successive responses always re-check and refresh the diff.
|
| 1592 |
+
Model output is converted from Markdown to HTML via the markdown library.
|
| 1593 |
"""
|
| 1594 |
SEPARATOR = (
|
| 1595 |
"<div style='text-align: center; color: #888888; margin: 16px 0; "
|
| 1596 |
"border-top: 1px solid #dddddd; padding-top: 10px;'>"
|
| 1597 |
+
"<em>― Follow-up ―</em></div>\n"
|
| 1598 |
)
|
| 1599 |
formatted = ""
|
| 1600 |
for i, r in enumerate(rounds):
|
| 1601 |
prompt = strip_context(r["prompt"]) if i == 0 else r["prompt"]
|
| 1602 |
+
prompt_html = md_lib.markdown(prompt, extensions=["fenced_code", "tables", "nl2br"])
|
| 1603 |
+
output_html = md_lib.markdown(r["output"], extensions=["fenced_code", "tables", "nl2br"])
|
| 1604 |
if i > 0:
|
| 1605 |
formatted += SEPARATOR
|
| 1606 |
formatted += (
|
| 1607 |
f"<div style='color: #0066cc; background-color: #f0f7ff; "
|
| 1608 |
f"padding: 10px; border-radius: 5px; margin-bottom: 10px;'>"
|
| 1609 |
+
f"<strong>User:</strong> {prompt_html}</div>\n"
|
| 1610 |
)
|
| 1611 |
formatted += (
|
| 1612 |
f"<div style='color: #006633; background-color: #f0fff0; "
|
| 1613 |
f"padding: 10px; border-radius: 5px; margin-bottom: 10px;'>"
|
| 1614 |
+
f"<strong>Model:</strong> {output_html}</div>\n"
|
| 1615 |
)
|
| 1616 |
if r.get("diff"):
|
| 1617 |
+
diff_html = md_lib.markdown(
|
| 1618 |
+
f"**Git Diff (cumulative after round {i + 1}):**\n"
|
| 1619 |
+
f"```diff\n{r['diff']}\n```",
|
| 1620 |
+
extensions=["fenced_code"],
|
| 1621 |
)
|
| 1622 |
+
formatted += diff_html + "\n"
|
| 1623 |
return formatted
|
| 1624 |
|
| 1625 |
|
requirements.txt
CHANGED
|
@@ -3,6 +3,7 @@ gradio[oauth]
|
|
| 3 |
gradio_leaderboard
|
| 4 |
httpx
|
| 5 |
huggingface_hub
|
|
|
|
| 6 |
openai
|
| 7 |
opencode-ai
|
| 8 |
pandas
|
|
|
|
| 3 |
gradio_leaderboard
|
| 4 |
httpx
|
| 5 |
huggingface_hub
|
| 6 |
+
markdown
|
| 7 |
openai
|
| 8 |
opencode-ai
|
| 9 |
pandas
|