Skip to content

Latest commit

Β 

History

History
149 lines (102 loc) Β· 5.29 KB

File metadata and controls

149 lines (102 loc) Β· 5.29 KB

Terminal Integration Summary - System Terminal in Fullstack Development Mode

Overview

The AliFullstack application includes a sophisticated terminal system that supports streaming backend commands (like Python) in fullstack development mode. The system intelligently routes commands to appropriate terminals based on command type and development mode.

Terminal Types

  • Frontend Terminal: For client-side commands (npm, yarn, node, vite, etc.)
  • Backend Terminal: For server-side commands (python, pip, django, flask, etc.)
  • Main Terminal: Default fallback terminal

Command Execution Flow

1. AI Response Processing (src/ipc/processors/response_processor.ts)

  • Parses AI responses for terminal command tags
  • Routes commands to appropriate terminals
  • Executes commands and streams output

2. Terminal Command Tags

  • <run_terminal_cmd> - General commands with intelligent routing
  • <alifullstack-run-backend-terminal-cmd> - Explicit backend commands
  • <alifullstack-run-frontend-terminal-cmd> - Explicit frontend commands

3. Intelligent Command Routing Logic

// Python/backend commands β†’ backend terminal
const isPythonCommand =
  cleanCommand.toLowerCase().includes("python") ||
  cleanCommand.toLowerCase().includes("pip") ||
  cleanCommand.toLowerCase().includes("conda");

// Node.js/frontend commands β†’ frontend terminal
const isNodeCommand =
  cleanCommand.toLowerCase().includes("npm") ||
  cleanCommand.toLowerCase().includes("yarn") ||
  cleanCommand.toLowerCase().includes("node");

4. Routing in Fullstack Mode

  • Python/pip commands β†’ Backend Terminal βœ…
  • npm/yarn/node commands β†’ Frontend Terminal
  • General commands β†’ Backend Terminal (default)

Key Files for System Terminal Modification

Core Processing Files

  1. src/ipc/processors/response_processor.ts - Main command execution logic

    • Lines 313-447: General terminal command processing
    • Lines 220-269: Backend terminal command processing
    • Lines 272-311: Frontend terminal command processing
  2. src/ipc/utils/alifullstack_tag_parser.ts - Tag parsing functions

    • getAliFullStackRunBackendTerminalCmdTags() - Backend command extraction
    • getAliFullStackRunFrontendTerminalCmdTags() - Frontend command extraction
    • getAliFullStackRunTerminalCmdTags() - General command extraction
  3. src/ipc/utils/runShellCommand.ts - Shell command execution

    • Synchronous command execution with stdout/stderr capture

Terminal Management Files

  1. src/ipc/handlers/terminal_handlers.ts - Terminal output routing

    • addTerminalOutput() - Adds formatted output to terminal atoms
    • Manages frontend/backend terminal state
  2. src/components/backend-chat/BackendChatInput.tsx - Terminal initialization

    • Lines 104-129: Initializes terminals in backend/fullstack mode
    • Sets up welcome messages and terminal state

Testing Files

  1. test_terminal_commands.js - Terminal command tag testing
    • Validates tag parsing and rendering logic

Current Python Streaming in Fullstack Mode

The system automatically streams Python commands to the backend terminal in fullstack mode:

if (isPythonCommand) {
  terminalType = "backend";
  // Ensures backend directory exists
  // Routes to backend terminal
}

Automatic Server Startup Implementation

βœ… Backend Server Auto-Start

The backend server now automatically starts when you run/restart fullstack apps through the preview panel.

βœ… Frontend Server Auto-Start (Fullstack Mode)

The frontend server now automatically starts when you run/restart fullstack apps through the preview panel.

Implementation Details

Server Startup Process:

The backend and frontend servers automatically start when you run/restart the app through the normal preview controls:

  1. Click "Run" or "Restart" in the Preview Panel
  2. App running process detects fullstack mode (both frontend/ and backend/ directories exist)
  3. Automatically starts both backend and frontend servers
  4. Streams output to appropriate terminals

Terminal Initialization:

When entering Backend/Fullstack chat modes, terminals are initialized and ready for command streaming:

  1. src/components/backend-chat/BackendChatInput.tsx - Terminal initialization
  2. src/ipc/handlers/terminal_handlers.ts - Terminal output routing
  3. src/ipc/processors/response_processor.ts - Command processing and routing

Server Startup Flow

User Clicks "Run" or "Restart" in Preview Panel
    ↓
executeApp() detects fullstack mode (frontend/ + backend/ exist)
    ↓
Backend server automatically starts
    ↓
Frontend server automatically starts
    ↓
Both servers stream output to respective terminals
    ↓
Preview iframe shows running app

Current Status

βœ… Python commands automatically routed to backend terminal in fullstack mode βœ… Backend server automatically starts when running fullstack apps βœ… Frontend server automatically starts when running fullstack apps βœ… Terminal output streams server output and command execution βœ… Preview panel works correctly without conflicts

The system provides automatic backend server streaming through the normal app running process, ensuring proper integration with the preview panel.