Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/cli_agent_orchestrator/cli/commands/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import json
import os
import re
import shlex

import click
import requests
Expand All @@ -24,6 +26,11 @@ def restore(terminal_id: str):
working directory and loads the saved scrollback history into the pane.
The session must still exist.
"""
if not re.fullmatch(r"[A-Za-z0-9_-]+", terminal_id):
raise click.ClickException(
f"Invalid terminal_id '{terminal_id}'. Only alphanumeric, underscore, and hyphen characters are allowed."
)
Comment on lines +29 to +32
Comment on lines +29 to +32

snapshot_path = TERMINAL_LOG_DIR / f"{terminal_id}.snapshot.json"
scrollback_path = TERMINAL_LOG_DIR / f"{terminal_id}.scrollback"

Expand Down Expand Up @@ -57,9 +64,9 @@ def restore(terminal_id: str):
login_shell = os.environ.get("SHELL", "bash")

if scrollback_path.exists():
window_shell = f"cat '{scrollback_path}'; exec {login_shell} -l"
window_shell = f"cat {shlex.quote(str(scrollback_path))}; exec {shlex.quote(login_shell)} -l"
else:
window_shell = f"exec {login_shell} -l"
window_shell = f"exec {shlex.quote(login_shell)} -l"

try:
get_backend().create_window(
Expand Down
Loading