Skip to content

Commit b913f97

Browse files
author
Agent Bot
committed
Fixed pip install to accept from pyproject.toml as well as other files instead of just req.txt
1 parent 7333275 commit b913f97

7 files changed

Lines changed: 54 additions & 23 deletions

File tree

app.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import streamlit as st
22
import os
33
import time
4+
import hashlib
45
from src.graph import create_ase_graph
56
from src.tools.github_tools import GitHubTool
67
from dotenv import load_dotenv
78

8-
# Load env but also allow manual override in sidebar
9+
# Load local .env (ignored if deployed on Streamlit Cloud)
910
load_dotenv()
1011

1112
st.set_page_config(
@@ -52,12 +53,22 @@
5253
st.image("Ghost_coder_logo.png", width=500)
5354
st.title("Settings")
5455

55-
st.markdown("### API Keys")
56-
gh_token = st.text_input("GitHub Token", value=os.getenv("GITHUB_TOKEN", ""), type="password")
57-
groq_key = st.text_input("Groq API Key", value=os.getenv("GROQ_API_KEY", ""), type="password")
56+
st.markdown("### Authentication")
57+
app_password = st.text_input("App Password", type="password", help="Enter the password to use this app.")
5858

59-
if gh_token: os.environ["GITHUB_TOKEN"] = gh_token
60-
if groq_key: os.environ["GROQ_API_KEY"] = groq_key
59+
# Load keys from Streamlit Secrets or .env
60+
gh_token = ""
61+
groq_key = ""
62+
expected_password = "demo" # Fallback password if not set
63+
64+
try:
65+
gh_token = st.secrets.get("GITHUB_TOKEN") or os.getenv("GITHUB_TOKEN", "")
66+
groq_key = st.secrets.get("GROQ_API_KEY") or os.getenv("GROQ_API_KEY", "")
67+
expected_password = st.secrets.get("APP_PASSWORD") or os.getenv("APP_PASSWORD", "demo")
68+
except Exception:
69+
gh_token = os.getenv("GITHUB_TOKEN", "")
70+
groq_key = os.getenv("GROQ_API_KEY", "")
71+
expected_password = os.getenv("APP_PASSWORD", "demo")
6172

6273

6374
# --- Main UI ---
@@ -87,12 +98,14 @@
8798
issue_url = st.text_input("Issue URL", placeholder="https://github.com/owner/repo/issues/123")
8899

89100
if st.button("Execute Autonomous Fix"):
90-
if not issue_url:
101+
if app_password != expected_password:
102+
st.error("Incorrect password.")
103+
elif not issue_url:
91104
st.warning("Please provide a GitHub Issue URL.")
92-
elif not os.getenv("GITHUB_TOKEN") or not os.getenv("GROQ_API_KEY"):
93-
st.error("Missing API keys. Please set them in the sidebar or .env file.")
105+
elif not gh_token or not groq_key:
106+
st.error("Missing API keys in Streamlit secrets or .env file.")
94107
else:
95-
gh_tool = GitHubTool()
108+
gh_tool = GitHubTool(token=gh_token)
96109

97110
with st.status("Initializing Environment...", expanded=True) as status:
98111
st.write("🔍 Fetching issue metadata...")
@@ -104,7 +117,8 @@
104117

105118
st.write(f"**Targeting:** {issue_info['title']}")
106119

107-
workspace_dir = os.path.abspath("./workspace_clones/target_repo")
120+
session_id = hashlib.md5(issue_url.encode()).hexdigest()[:8]
121+
workspace_dir = os.path.abspath(f"./workspace_clones/target_repo_{session_id}")
108122
st.write("📂 Cloning repository to workspace...")
109123
if not gh_tool.clone_repository(issue_url, workspace_dir):
110124
st.error("Failed to clone repository. Workspace may be locked.")
@@ -117,6 +131,8 @@
117131
"issue_url": issue_url,
118132
"issue_description": f"{issue_info['title']}\n\n{issue_info['body']}",
119133
"repo_path": workspace_dir,
134+
"github_token": gh_token,
135+
"groq_api_key": groq_key,
120136
"files_to_modify": [],
121137
"research_summary": "",
122138
"updated_code": {},
@@ -179,7 +195,7 @@
179195
st.header("🚀 Deployment Pipeline (Human-in-the-Loop)")
180196

181197
final_state = st.session_state.final_state
182-
gh_tool = GitHubTool()
198+
gh_tool = GitHubTool(token=final_state["github_token"])
183199
repo_path = final_state["repo_path"]
184200
issue_url = final_state["issue_url"]
185201
files_to_update = list(final_state["updated_code"].keys())

src/agents/coder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def coder_node(state: ASEState):
99
Provide the full content of the updated file.
1010
"""
1111
print("--- CODING FIX ---")
12-
llm = ChatGroq(model_name="llama-3.3-70b-versatile")
13-
gh_tool = GitHubTool()
12+
llm = ChatGroq(model_name="llama-3.3-70b-versatile", api_key=state.get("groq_api_key"))
13+
gh_tool = GitHubTool(token=state.get("github_token"))
1414

1515
updated_code = {}
1616
test_script = ""

src/agents/researcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def researcher_node(state: ASEState):
99
Output the filename and a code snippet of the problem area.
1010
"""
1111
print("--- RESEARCHING ISSUE ---")
12-
llm = ChatGroq(model_name="llama-3.3-70b-versatile")
13-
gh_tool = GitHubTool()
12+
llm = ChatGroq(model_name="llama-3.3-70b-versatile", api_key=state.get("groq_api_key"))
13+
gh_tool = GitHubTool(token=state.get("github_token"))
1414

1515
# 1. Get repo context (file tree)
1616
tree = gh_tool.list_files_tree(state["repo_path"])

src/agents/tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def tester_node(state: ASEState):
88
Run it in the sandbox. If it fails, explain why to the coder.
99
"""
1010
print("--- TESTING FIX ---")
11-
llm = ChatGroq(model_name="llama-3.3-70b-versatile")
11+
llm = ChatGroq(model_name="llama-3.3-70b-versatile", api_key=state.get("groq_api_key"))
1212
sandbox = DockerSandbox()
1313

1414
test_script_content = state.get("test_script", "")

src/state.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class ASEState(TypedDict):
88
issue_description: str
99
repo_path: str
1010

11+
# API Keys
12+
github_token: str
13+
groq_api_key: str
14+
1115
# Researcher Output
1216
files_to_modify: List[str]
1317
research_summary: str

src/tools/docker_sandbox.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io
55

66
class DockerSandbox:
7-
def __init__(self, image="python:3.11-slim"):
7+
def __init__(self, image="python:3.11"):
88
self.client = docker.from_env()
99
self.image = image
1010

@@ -20,8 +20,12 @@ def run_test(self, repo_path: str, test_script_content: str, test_file_name="tes
2020
f.write(test_script_content)
2121

2222
# 2. Create container and start it with the repo path mounted
23-
# We use a shell command to install requirements before running the test
24-
setup_and_run_cmd = f"if [ -f requirements.txt ]; then pip install -r requirements.txt; fi && python {test_file_name}"
23+
# We intelligently install project dependencies so standard packages (like pandas) are available
24+
setup_and_run_cmd = (
25+
"if [ -f pyproject.toml ] || [ -f setup.py ]; then pip install -e . || pip install . ; fi; "
26+
"if [ -f requirements.txt ]; then pip install -r requirements.txt; fi; "
27+
f"python {test_file_name}"
28+
)
2529

2630
container = self.client.containers.run(
2731
self.image,

src/tools/github_tools.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
load_dotenv()
88

99
class GitHubTool:
10-
def __init__(self):
11-
self.token = os.getenv("GITHUB_TOKEN")
10+
def __init__(self, token: str = None):
11+
self.token = token or os.getenv("GITHUB_TOKEN")
1212
if self.token:
1313
self.client = Github(self.token)
1414
else:
@@ -55,6 +55,11 @@ def clone_repository(self, issue_url: str, dest_dir: str) -> bool:
5555

5656
try:
5757
if os.path.exists(os.path.join(dest_dir, ".git")):
58+
# Reset to clean state for retry
59+
subprocess.run(['git', 'reset', '--hard', 'origin/HEAD'], cwd=dest_dir, check=False)
60+
subprocess.run(['git', 'clean', '-fd'], cwd=dest_dir, check=False)
61+
# Also pull latest in case the user merged the PR
62+
subprocess.run(['git', 'pull'], cwd=dest_dir, check=False)
5863
return True
5964

6065
if not os.path.exists(dest_dir) or not os.listdir(dest_dir):
@@ -103,9 +108,11 @@ def read_file(self, repo_path: str, file_path: str) -> str:
103108

104109
def run_git_command(self, repo_path: str, command: list) -> str:
105110
"""Executes a git command and returns the output."""
111+
# Security mitigation: disable git hooks on the host to prevent sandbox escape
112+
secure_command = ['-c', 'core.hooksPath=/dev/null'] + command
106113
try:
107114
result = subprocess.run(
108-
['git'] + command,
115+
['git'] + secure_command,
109116
cwd=repo_path,
110117
capture_output=True,
111118
text=True,

0 commit comments

Comments
 (0)