Skip to content

Commit 01ec831

Browse files
committed
Updates
1 parent 766a0a5 commit 01ec831

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

safeexecute/__init__.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,20 @@ def execute_github_copilot(
315315
with open(prompt_file, "w") as f:
316316
f.write(prompt)
317317

318-
# Build command that reads from the prompt file
319-
cmd = f'copilot -p "$(cat /workspace/.copilot_prompt.txt)" --model {model} --allow-all --no-auto-update'
318+
# Session file for capturing session ID
319+
session_file = "/workspace/.copilot_session.md"
320+
321+
# Build command that reads from the prompt file and exports session
322+
cmd = f'copilot -p "$(cat /workspace/.copilot_prompt.txt)" --model {model} --allow-all --no-auto-update --share {session_file}'
320323
if session_id:
321324
cmd += f" --resume {session_id}"
322325

326+
# Create a persistent config directory for Copilot sessions
327+
# This allows session resumption across container runs
328+
copilot_config_dir = os.path.join(working_directory, ".copilot_config")
329+
if not os.path.exists(copilot_config_dir):
330+
os.makedirs(copilot_config_dir)
331+
323332
# Run the CLI in the container
324333
container = client.containers.run(
325334
IMAGE_NAME,
@@ -328,7 +337,11 @@ def execute_github_copilot(
328337
os.path.abspath(docker_volume_path): {
329338
"bind": "/workspace",
330339
"mode": "rw",
331-
}
340+
},
341+
os.path.abspath(copilot_config_dir): {
342+
"bind": "/root/.copilot",
343+
"mode": "rw",
344+
},
332345
},
333346
working_dir="/workspace",
334347
environment={
@@ -344,7 +357,6 @@ def execute_github_copilot(
344357

345358
# Collect output
346359
all_output = []
347-
result_session_id = session_id # Keep the session ID if resuming
348360

349361
try:
350362
# Stream the container logs in real-time
@@ -372,6 +384,25 @@ def execute_github_copilot(
372384
if os.path.exists(prompt_file):
373385
os.remove(prompt_file)
374386

387+
# Parse session ID from the session markdown file
388+
session_md_path = os.path.join(working_directory, ".copilot_session.md")
389+
result_session_id = session_id # Default to the input session_id
390+
if os.path.exists(session_md_path):
391+
try:
392+
with open(session_md_path, "r") as f:
393+
session_content = f.read()
394+
# Look for session ID pattern: > **Session ID:** `uuid`
395+
import re
396+
397+
session_match = re.search(
398+
r"\*\*Session ID:\*\*\s*`([a-f0-9-]+)`", session_content
399+
)
400+
if session_match:
401+
result_session_id = session_match.group(1)
402+
os.remove(session_md_path)
403+
except Exception as e:
404+
logging.warning(f"Error parsing session file: {str(e)}")
405+
375406
# Parse the output
376407
full_output = "".join(all_output)
377408

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="safeexecute",
10-
version="0.0.18",
10+
version="0.0.19",
1111
description="Safe way to execute Python code with containerization.",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)