Skip to content

Commit d9c1fba

Browse files
committed
feat: clone repos at runtime via invoke_command for fresh code on each review
Add invoke_command helper to execute shell commands on the harness runtime. Clone repos before agent invocation so code is always up to date instead of relying on stale pre-cloned images.
1 parent 5271f55 commit d9c1fba

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/scripts/python/harness_review.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,45 @@ def read_prompt(filename):
3535
return f.read()
3636

3737

38+
def invoke_command(harness_arn, command, region, timeout=300):
39+
"""Execute a shell command on the harness runtime via invoke_agent_runtime_command."""
40+
session = boto3.Session(region_name=region)
41+
credentials = session.get_credentials().get_frozen_credentials()
42+
url = f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/command?agentRuntimeArn={quote(harness_arn, safe='')}"
43+
body = json.dumps({"command": command, "timeout": timeout})
44+
request = AWSRequest(method="POST", url=url, data=body, headers={
45+
"Content-Type": "application/json",
46+
"Accept": "application/vnd.amazon.eventstream",
47+
})
48+
SigV4Auth(credentials, "bedrock-agentcore", region).add_auth(request)
49+
resp = urllib3.PoolManager().urlopen(
50+
"POST", url, body=body,
51+
headers=dict(request.headers),
52+
preload_content=False,
53+
timeout=urllib3.Timeout(connect=10, read=timeout + 30),
54+
)
55+
if resp.status != 200:
56+
print(f" {RED}ERROR: HTTP {resp.status}: {resp.read().decode('utf-8')}{RESET}")
57+
return False
58+
buf = EventStreamBuffer()
59+
for chunk in resp.stream(4096):
60+
buf.add_data(chunk)
61+
for event in buf:
62+
event_type = event.headers.get(":event-type", "")
63+
if not event.payload:
64+
continue
65+
payload = json.loads(event.payload.decode("utf-8"))
66+
if event_type == "contentDelta":
67+
text = payload.get("delta", {}).get("text", "")
68+
if text:
69+
print(f" {text}", end="", flush=True)
70+
elif event_type == "contentStop":
71+
exit_code = payload.get("exitCode", -1)
72+
print(f"\n Exit code: {exit_code}")
73+
return exit_code == 0
74+
return True
75+
76+
3877
def invoke_harness(harness_arn, body, region):
3978
"""Send a SigV4-signed request to the harness invoke endpoint. Returns a streaming response.
4079
@@ -197,6 +236,18 @@ def flush_text():
197236
print(f"{CYAN}Harness:{RESET} {HARNESS_ARN}")
198237
print()
199238

239+
# Clone repos fresh on the runtime so the agent always has latest code
240+
print(f"{CYAN}Cloning repos on runtime...{RESET}")
241+
clone_cmds = [
242+
"git clone https://github.com/aws/agentcore-cli.git /opt/workspace/agentcore-cli",
243+
"git clone https://github.com/aws/agentcore-l3-cdk-constructs.git /opt/workspace/agentcore-l3-cdk-constructs",
244+
]
245+
for cmd in clone_cmds:
246+
print(f" $ {cmd}")
247+
if not invoke_command(HARNESS_ARN, cmd, REGION):
248+
print(f" {YELLOW}Warning: clone failed, agent may lack repo context{RESET}")
249+
print()
250+
200251
SYSTEM_PROMPT = read_prompt("system.md")
201252
REVIEW_PROMPT = read_prompt("review.md").format(pr_url=PR_URL)
202253

0 commit comments

Comments
 (0)