feat: implement perfect version of the core rendering pipeline with optimized shader compilation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import time
|
||||
from pr.ui import Colors
|
||||
from pr.tools import read_file
|
||||
from pr.tools.base import get_tools_definition
|
||||
@@ -143,6 +144,9 @@ def handle_command(assistant, command):
|
||||
elif cmd == '/stats':
|
||||
show_system_stats(assistant)
|
||||
|
||||
elif cmd.startswith('/bg'):
|
||||
handle_background_command(assistant, command)
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -389,3 +393,141 @@ def show_system_stats(assistant):
|
||||
print(f" API cache entries: {cache_stats['api_cache']['valid_entries']}")
|
||||
if 'tool_cache' in cache_stats:
|
||||
print(f" Tool cache entries: {cache_stats['tool_cache']['valid_entries']}")
|
||||
|
||||
def handle_background_command(assistant, command):
|
||||
"""Handle background multiplexer commands."""
|
||||
parts = command.strip().split(maxsplit=2)
|
||||
if len(parts) < 2:
|
||||
print(f"{Colors.RED}Usage: /bg <subcommand> [args]{Colors.RESET}")
|
||||
print(f"{Colors.GRAY}Available subcommands: start, list, status, output, input, kill, events{Colors.RESET}")
|
||||
return
|
||||
|
||||
subcmd = parts[1].lower()
|
||||
|
||||
try:
|
||||
if subcmd == 'start' and len(parts) >= 3:
|
||||
session_name = f"bg_{len(parts[2].split())}_{int(time.time())}"
|
||||
start_background_session(assistant, session_name, parts[2])
|
||||
elif subcmd == 'list':
|
||||
list_background_sessions(assistant)
|
||||
elif subcmd == 'status' and len(parts) >= 3:
|
||||
show_session_status(assistant, parts[2])
|
||||
elif subcmd == 'output' and len(parts) >= 3:
|
||||
show_session_output(assistant, parts[2])
|
||||
elif subcmd == 'input' and len(parts) >= 4:
|
||||
send_session_input(assistant, parts[2], parts[3])
|
||||
elif subcmd == 'kill' and len(parts) >= 3:
|
||||
kill_background_session(assistant, parts[2])
|
||||
elif subcmd == 'events':
|
||||
show_background_events(assistant)
|
||||
else:
|
||||
print(f"{Colors.RED}Unknown background command: {subcmd}{Colors.RESET}")
|
||||
print(f"{Colors.GRAY}Available: start, list, status, output, input, kill, events{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error executing background command: {e}{Colors.RESET}")
|
||||
|
||||
def start_background_session(assistant, session_name, command):
|
||||
"""Start a command in background."""
|
||||
try:
|
||||
from pr.multiplexer import start_background_process
|
||||
result = start_background_process(session_name, command)
|
||||
|
||||
if result['status'] == 'success':
|
||||
print(f"{Colors.GREEN}Started background session '{session_name}' with PID {result['pid']}{Colors.RESET}")
|
||||
else:
|
||||
print(f"{Colors.RED}Failed to start background session: {result.get('error', 'Unknown error')}{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error starting background session: {e}{Colors.RESET}")
|
||||
|
||||
def list_background_sessions(assistant):
|
||||
"""List all background sessions."""
|
||||
try:
|
||||
from pr.ui.display import display_multiplexer_status
|
||||
from pr.multiplexer import get_all_sessions
|
||||
|
||||
sessions = get_all_sessions()
|
||||
display_multiplexer_status(sessions)
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error listing background sessions: {e}{Colors.RESET}")
|
||||
|
||||
def show_session_status(assistant, session_name):
|
||||
"""Show status of a specific session."""
|
||||
try:
|
||||
from pr.multiplexer import get_session_info
|
||||
|
||||
info = get_session_info(session_name)
|
||||
if info:
|
||||
print(f"{Colors.BOLD}Session '{session_name}':{Colors.RESET}")
|
||||
print(f" Status: {info.get('status', 'unknown')}")
|
||||
print(f" PID: {info.get('pid', 'N/A')}")
|
||||
print(f" Command: {info.get('command', 'N/A')}")
|
||||
if 'start_time' in info:
|
||||
import time
|
||||
elapsed = time.time() - info['start_time']
|
||||
print(f" Running for: {elapsed:.1f}s")
|
||||
else:
|
||||
print(f"{Colors.YELLOW}Session '{session_name}' not found{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error getting session status: {e}{Colors.RESET}")
|
||||
|
||||
def show_session_output(assistant, session_name):
|
||||
"""Show output of a specific session."""
|
||||
try:
|
||||
from pr.multiplexer import get_session_output
|
||||
|
||||
output = get_session_output(session_name, lines=50)
|
||||
if output:
|
||||
print(f"{Colors.BOLD}Recent output from '{session_name}':{Colors.RESET}")
|
||||
print(f"{Colors.GRAY}{'─' * 60}{Colors.RESET}")
|
||||
for line in output:
|
||||
print(line)
|
||||
else:
|
||||
print(f"{Colors.YELLOW}No output available for session '{session_name}'{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error getting session output: {e}{Colors.RESET}")
|
||||
|
||||
def send_session_input(assistant, session_name, input_text):
|
||||
"""Send input to a background session."""
|
||||
try:
|
||||
from pr.multiplexer import send_input_to_session
|
||||
|
||||
result = send_input_to_session(session_name, input_text)
|
||||
if result['status'] == 'success':
|
||||
print(f"{Colors.GREEN}Input sent to session '{session_name}'{Colors.RESET}")
|
||||
else:
|
||||
print(f"{Colors.RED}Failed to send input: {result.get('error', 'Unknown error')}{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error sending input: {e}{Colors.RESET}")
|
||||
|
||||
def kill_background_session(assistant, session_name):
|
||||
"""Kill a background session."""
|
||||
try:
|
||||
from pr.multiplexer import kill_session
|
||||
|
||||
result = kill_session(session_name)
|
||||
if result['status'] == 'success':
|
||||
print(f"{Colors.GREEN}Session '{session_name}' terminated{Colors.RESET}")
|
||||
else:
|
||||
print(f"{Colors.RED}Failed to kill session: {result.get('error', 'Unknown error')}{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error killing session: {e}{Colors.RESET}")
|
||||
|
||||
def show_background_events(assistant):
|
||||
"""Show recent background events."""
|
||||
try:
|
||||
from pr.core.background_monitor import get_global_monitor
|
||||
|
||||
monitor = get_global_monitor()
|
||||
events = monitor.get_pending_events()
|
||||
|
||||
if events:
|
||||
print(f"{Colors.BOLD}Recent Background Events:{Colors.RESET}")
|
||||
print(f"{Colors.GRAY}{'─' * 60}{Colors.RESET}")
|
||||
|
||||
for event in events[-10:]: # Show last 10 events
|
||||
from pr.ui.display import display_background_event
|
||||
display_background_event(event)
|
||||
else:
|
||||
print(f"{Colors.GRAY}No recent background events{Colors.RESET}")
|
||||
except Exception as e:
|
||||
print(f"{Colors.RED}Error getting background events: {e}{Colors.RESET}")
|
||||
|
||||
Reference in New Issue
Block a user