Commit Graph

14 Commits

  • feat: Implement CLI session-based Full Stack mode
    Replaces WebContainer-based approach with simpler Claude Code CLI session
    shell command execution. This eliminates COOP/COEP header requirements
    and reduces bundle size by ~350KB.
    
    Changes:
    - Added executeShellCommand() to ClaudeService for spawning bash processes
    - Added /claude/api/shell-command API endpoint for executing commands
    - Updated Full Stack mode (chat-functions.js) to use CLI sessions
    - Simplified terminal mode by removing WebContainer dependencies
    
    Benefits:
    - No SharedArrayBuffer/COOP/COEP issues
    - Uses existing Claude Code infrastructure
    - Faster startup, more reliable execution
    - Better error handling and output capture
    
    Fixes:
    - Terminal creation failure in Full Stack mode
    - WebContainer SharedArrayBuffer serialization errors
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • feat: implement HTTP polling to bypass WebSocket issue
    The WebSocket closes immediately with code 1006 due to nginx/proxy
    issues. This implementation completely bypasses WebSocket for
    terminal output by using HTTP polling instead.
    
    Architecture:
    - Server buffers PTY output in memory (outputBuffer array)
    - Frontend polls every 100ms via GET /terminals/:id/output?since=N
    - Output entries have monotonically increasing index
    - Old output is automatically cleaned up after 5 minutes
    - Commands sent via HTTP POST (already implemented)
    
    Changes:
    - terminal-service.js: Added bufferOutput(), getTerminalOutput()
    - terminal.js: Added startPolling(), stopPolling(), sendTerminalResize()
    - server.js: Added GET /terminals/:id/output and POST /terminals/:id/resize
    - No WebSocket needed for output display (keeps legacy compatibility)
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • fix: remove debug panel close button to keep it always visible
    The close button would hide the debug panel with display: none,
    making it impossible to see debug messages without reloading.
    
    Also includes HTTP POST workaround changes for terminal command
    execution that bypass the WebSocket send issue.
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • fix: terminal command execution via HTTP POST workaround
    The WebSocket send mechanism fails with close code 1006 when client
    tries to send data to server. Server never receives the message,
    indicating a network/proxy layer issue that couldn't be fixed through
    code changes or nginx configuration.
    
    Solution: Bypass WebSocket send entirely by using HTTP POST to send
    commands directly to the PTY.
    
    Changes:
    - Added sendTerminalInput() method to terminal-service.js that writes
      directly to PTY, bypassing WebSocket
    - Added POST endpoint /claude/api/terminals/:id/input to server.js
    - Modified launchCommand() in terminal.js to use fetch() with HTTP
      POST instead of WebSocket.send()
    
    The WebSocket receive direction still works (server→client for output
    display), only send direction (client→server for commands) is bypassed.
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • debug: add detailed spawn attempt and error logging
    - Log spawn attempt before calling spawn()
    - Add detailed error logging with stack trace
    - This will help identify if spawn is failing silently
  • debug: add PTY lifecycle logging
    - Log PTY PID and shell when spawned
    - Log all PTY output data
    - Log PTY exit events with exit code and signal
    - Log when WebSocket cannot send PTY data
    
    This will help identify if the PTY is exiting immediately
    or if there's an issue with the PTY process.
  • debug: add visual debug panel and comprehensive logging
    - Added debug panel in terminal view that shows all terminal activity
    - Added debugLog() method to TerminalManager for consistent logging
    - Updated connectTerminal, handleTerminalMessage, launchCommand, createTerminal, initializeXTerm with detailed logging
    - Enhanced backend logging for WebSocket messages and close codes
    - Logs now show both to console and visual debug panel
    
    This should help diagnose the terminal command execution issue without
    requiring browser console access.
  • debug: add comprehensive logging for terminal command flow
    Phase 1 of systematic debugging: Gather evidence
    
    Added detailed logging to trace the complete command flow:
    - launchCommand: Shows when called, terminalId, command, WebSocket state
    - waitForTerminalReady: Shows waiting period and ready state
    - handleTerminalMessage: Shows all messages from backend with details
    - WebSocket message content logged before sending
    
    Also fixed duplicate 'ready' message (removed line 113-116).
    
    Now when user creates "Claude Code CLI" terminal, console will show:
    1. launchCommand called with terminalId and command
    2. Waiting for terminal ready
    3. Ready message received (or timeout)
    4. Command sent to WebSocket
    5. All backend messages logged
    
    This will reveal exactly where the flow breaks.
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • fix: backend sends ready message when WebSocket connects
    Critical fix: The frontend was waiting for a 'ready' message that the
    backend never sent, causing commands to timeout.
    
    Root Cause:
    Frontend connectTerminal() waits for 'ready' message from backend
    before resolving, but backend never sent this message. Result: Frontend
    timed out after 5 seconds waiting for ready state, and commands were
    never sent.
    
    Fix:
    Send 'ready' message immediately when WebSocket connection is established.
    This signals to frontend that PTY is initialized and ready to receive input.
    
    Flow Now:
    1. Frontend creates terminal UI
    2. Frontend initializes xterm.js
    3. Frontend connects WebSocket
    4. Backend receives connection, sends 'ready' message
    5. Frontend receives 'ready', sets ready=true, resolves promise
    6. Frontend sends claude --dangerously-skip-permissions command
    7. Command executes successfully
    
    Resolves: "still getting empty terminal"
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • feat: add session move endpoint and project-session cascading delete
    - Add sessions table to database with projectId and deletedAt columns
    - Create POST /api/sessions/:id/move endpoint to reassign sessions
    - Update DELETE /api/projects/:id to cascade soft-delete to sessions
    - Support moving sessions between projects or to unassigned state
    - Handle both active (in-memory) and historical sessions
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • fix: add input validation and fix unique constraint
    Fixed code quality issues from Task 2 review:
    
    1. Added ID validation in PUT endpoint:
       - Validates req.params.id is a valid positive integer
       - Returns 400 for invalid IDs (non-numeric, negative, zero, decimals)
       - Prevents SQL injection attempts
    
    2. Added path validation in POST and PUT endpoints:
       - Validates projectPath is absolute path
       - Normalizes and resolves paths
       - Detects and blocks path traversal attempts (e.g., ../../../etc)
       - Returns 400 for invalid paths
    
    3. Fixed UNIQUE constraint in database schema:
       - Removed UNIQUE constraint from name column
       - Allows creating projects with same name as deleted projects
       - Application-level duplicate checking remains for active projects
       - Added table migration to drop and recreate schema
    
    Files modified:
    - server.js: Added validateProjectId() and validateProjectPath() helpers
    - services/database.js: Removed UNIQUE constraint, added migration
    
    All validation tested and working correctly.
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • feat: add SQLite database and projects table schema
    - Install better-sqlite3 package for persistent storage
    - Create database service with projects table schema
    - Add indexes on deletedAt and name for efficient queries
    - Support soft-delete with deletedAt timestamp
    - Export database instance for use in server.js
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  • Initial commit: Obsidian Web Interface for Claude Code
    - Full IDE with terminal integration using xterm.js
    - Session management with local and web sessions
    - HTML preview functionality
    - Multi-terminal support with session picker
    
    Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>