Skip to content

Split terminal.py into focused modules (PTY, sessions, commands) #210

Description

@mrveiss

Parent Issue

Part of #185 (Split oversized Python files)

Current State

  • backend/api/terminal.py: 2054 lines, 23 functions
  • Models already extracted to terminal_models.py (137 lines) ✅

Tasks

  • Extract PTY management to terminal_pty.py
  • Extract session management to terminal_sessions.py
  • Extract command execution to terminal_commands.py
  • Extract WebSocket handlers to terminal_websocket.py
  • Keep only routing in main terminal.py

Acceptance Criteria

  • Each module has < 20 functions
  • Clear single responsibility per module
  • All imports updated
  • All tests pass

File Structure After Split

backend/api/
├── terminal.py            # Router only
├── terminal_models.py     # Pydantic models (done ✅)
├── terminal_pty.py        # PTY process management
├── terminal_sessions.py   # Session lifecycle
├── terminal_commands.py   # Command execution
└── terminal_websocket.py  # WebSocket handlers

Activity

  1. mrveiss commented on Nov 28, 2025

    @mrveiss
    OwnerAuthor

    Issue #210 Complete ✅

    Successfully split terminal.py into focused modules:

    Extractions Completed:

    1. terminal_models.py (137 lines) - Pydantic models (previously done)
    2. terminal_handlers.py (1176 lines) - Handler classes:
      • ConsolidatedTerminalWebSocket - WebSocket I/O handler
      • ConsolidatedTerminalManager - Session lifecycle management
      • session_manager - Global instance

    Results:

    • Original: terminal.py 2054 lines
    • Final: terminal.py 921 lines
    • Total Reduction: 1133 lines extracted (-55%)

    Commit:

    • a821fe01 - Extract handler classes to terminal_handlers.py

    File Structure:

    backend/api/
    ├── terminal.py            # 921 lines - REST API endpoints only
    ├── terminal_models.py     # 137 lines - Pydantic models
    └── terminal_handlers.py   # 1176 lines - Handler classes
    

    The terminal.py file is now at a reasonable size with clear single responsibility (API routing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions