Home · Developers · Guides · Editor System

Workspace

Editor System

Editor engine internals

Overview

The Editor System provides a comprehensive file editing interface for the Nova Coder web application. It allows users to browse files, read file contents, save file changes, and apply text-based edits. The system integrates with the workspace service to provide seamless file management capabilities.

Features

File Browsing

  • Directory Navigation - Navigate through workspace directory structures
  • File Listing - List files and directories with metadata
  • Path Traversal - Support for relative and absolute paths
  • File Metadata - Display file size, type, and modification information

File Operations

  • Read File - Retrieve file contents for viewing and editing
  • Save File - Save file contents with automatic directory creation
  • Apply Edit - Apply text replacement edits to files
  • File Validation - Validate file paths and permissions

Code Search & Analysis

  • Code Search - Search for code patterns across files in the workspace
  • Symbol Extraction - Extract code symbols (functions, classes, variables) from files
  • Code Formatting - Format code according to language-specific rules
  • Collaboration - Handle real-time collaboration events for multi-user editing

API Endpoints

GET /api/editor/files

  • Summary: List Files
  • Description: Lists files in the workspace with optional path parameter
  • Query Parameters:
    • path (optional) - Directory path to list
  • Response:
    {
      "files": [
        {
          "name": "example.py",
          "path": "src/example.py",
          "type": "file",
          "size": 1024
        },
        {
          "name": "tests",
          "path": "src/tests",
          "type": "directory",
          "size": 0
        }
      ],
      "total": 2,
      "current_path": "src"
    }
    

GET /api/editor/file

  • Summary: Get File Content
  • Description: Returns the content of a file
  • Query Parameters:
    • path (required) - File path
  • Response:
    {
      "path": "src/example.py",
      "content": "print('hello world')",
      "size": 20
    }
    

POST /api/editor/file

  • Summary: Save File Content
  • Description: Saves content to a file (creates parent directories as needed)
  • Request Body:
    {
      "path": "src/example.py",
      "content": "print('hello world')"
    }
    
  • Response:
    {
      "success": true,
      "path": "src/example.py",
      "size": 20
    }
    

POST /api/editor/apply-edit

  • Summary: Apply Edit
  • Description: Applies a text replacement edit to a file
  • Request Body:
    {
      "path": "src/example.py",
      "old_text": "print('hello')",
      "new_text": "print('hello world')"
    }
    
  • Response:
    {
      "success": true,
      "path": "src/example.py",
      "changes": 1
    }
    
  • Summary: Search Code
  • Description: Search for code across files in the workspace
  • Query Parameters:
    • query (required) - Search query string
    • regex (optional) - Enable regex search (default: false)
    • file_pattern (optional) - File pattern to search (default: "*")
  • Response:
    {
      "results": [
        {
          "file": "src/example.py",
          "line": 10,
          "content": "print('hello world')",
          "match": "hello"
        }
      ],
      "total": 1
    }
    

GET /api/editor/symbols

  • Summary: Get File Symbols
  • Description: Extract code symbols from a file
  • Query Parameters:
    • path (required) - File path
  • Response:
    {
      "path": "src/example.py",
      "symbols": [
        {
          "name": "main",
          "type": "function",
          "line": 1,
          "column": 0
        },
        {
          "name": "MyClass",
          "type": "class",
          "line": 10,
          "column": 0
        }
      ],
      "total": 2
    }
    

POST /api/editor/format

  • Summary: Format Code
  • Description: Format code in a file according to language-specific rules
  • Request Body:
    {
      "path": "src/example.py"
    }
    
  • Response:
    {
      "path": "src/example.py",
      "formatted": true,
      "changes": 5
    }
    

POST /api/editor/collaborate

  • Summary: Collaborate on File
  • Description: Handle real-time collaboration events for multi-user editing
  • Request Body:
    {
      "event_type": "cursor_update",
      "path": "src/example.py",
      "data": {
        "line": 10,
        "column": 5
      },
      "timestamp": "2024-01-15T10:30:00Z"
    }
    
  • Response:
    {
      "event_type": "cursor_update",
      "path": "src/example.py",
      "broadcast": true
    }
    

API Usage

Listing Files

// List files in root directory
const files = await api('/api/editor/files');
console.log('Files:', files.files);

// List files in specific directory
const srcFiles = await api('/api/editor/files?path=src');
console.log('Source files:', srcFiles.files);

Reading File Content

// Read file content
const file = await api('/api/editor/file?path=src/example.py');
console.log('Content:', file.content);
console.log('Size:', file.size);

Saving File Content

// Save file content
await api('/api/editor/file', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    path: 'src/new_file.py',
    content: 'print("new file")'
  })
});

Applying Edits

// Apply text replacement edit
await api('/api/editor/apply-edit', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    path: 'src/example.py',
    old_text: 'print("hello")',
    new_text: 'print("hello world")'
  })
});

Searching Code

// Search for code pattern
const results = await api('/api/editor/search?query=hello&file_pattern=*.py');
console.log('Search results:', results.results);

// Search with regex
const regexResults = await api('/api/editor/search?query=def.*test&regex=true');
console.log('Regex results:', regexResults.results);

Getting File Symbols

// Get symbols from a file
const symbols = await api('/api/editor/symbols?path=src/example.py');
console.log('Symbols:', symbols.symbols);

Formatting Code

// Format code in a file
await api('/api/editor/format', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    path: 'src/example.py'
  })
});

Collaboration Events

// Send cursor update
await api('/api/editor/collaborate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    event_type: 'cursor_update',
    path: 'src/example.py',
    data: { line: 10, column: 5 },
    timestamp: new Date().toISOString()
  })
});

// Send edit event
await api('/api/editor/collaborate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    event_type: 'edit',
    path: 'src/example.py',
    data: { changes: [...] },
    timestamp: new Date().toISOString()
  })
});

Web UI Integration

Location: novacoder/web/react/src/pages/Editor.tsx - renderEditor() function

Web UI Features

  • File Browser: Tree view of workspace files and directories
  • Code Editor: Syntax-highlighted code editor with line numbers
  • File Operations: Create, read, save, and edit files
  • Code Search: Search across files with regex support
  • Symbol Navigation: Extract and navigate code symbols
  • Code Formatting: Auto-format code according to language rules
  • Real-time Collaboration: Multi-user editing with cursor sync
  • Auto-save: Optional automatic file saving
  • Language Detection: Automatic language detection based on file extension

Web UI API Integration

  • GET /api/editor/files - List files in directory
  • GET /api/editor/file - Get file content
  • POST /api/editor/file - Save file content
  • POST /api/editor/upload - Upload file (multipart/form-data)
  • POST /api/editor/apply-edit - Apply text replacement edits
  • GET /api/editor/search - Search code across files
  • GET /api/editor/symbols - Extract code symbols from file
  • POST /api/editor/format - Format code in file
  • POST /api/editor/collaborate - Handle collaboration events

Web UI Usage

// The renderEditor() function is called when navigating to the Editor page
async function renderEditor(){
  // Render UI structure with file browser and code editor
  $('content').innerHTML = `...`;

  // Load initial file list
  const files = await api('/api/editor/files');
  renderFileTree(files.files);

  // Load file content when selected
  async function loadFile(path){
    const file = await api(`/api/editor/file?path=${path}`);
    editor.setValue(file.content);
  }

  // Save file content
  async function saveFile(path, content){
    await api('/api/editor/file', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ path, content })
    });
  }

  // Apply edit
  async function applyEdit(path, oldText, newText){
    await api('/api/editor/apply-edit', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ path, old_text: oldText, new_text: newText })
    });
  }
}

TUI Integration

The Editor system is integrated into the Terminal User Interface (TUI) through the Files and Editor pages.

TUI Features

  • File Browser: Navigate and select files
  • File Viewer: View file contents with syntax highlighting
  • File Editor: Edit file contents directly in TUI
  • File Operations: Create, delete, rename, and move files

TUI Usage

Access the editor in the TUI:

  • Navigate to the Files page to browse
  • Select a file to view its contents
  • Press 'E' to edit the file
  • Save changes with Ctrl+S
  • Navigate directories with arrow keys

Service Integration

The Editor system integrates with the following services:

  • WorkspaceService - Provides workspace path and file operations
  • File System - Direct file system access for file operations

Service Resolution

from novacoder.workspace.service import WorkspaceService

workspace_service = _nova_app.container.resolve(WorkspaceService)

Configuration

Default Configuration

The Editor system uses the default workspace configuration. No specific configuration is required for the editor endpoints.

Customization

To customize editor behavior, modify the endpoint implementations in novacoder/api/routes_editor_system.py:

  • Add file validation rules
  • Implement file type restrictions
  • Add file size limits
  • Customize error messages

Error Handling

Application Not Running

If the application is not running, the endpoints return:

{
  "error": "Application not running"
}

Status code: 503

Invalid Path

If the path is invalid or does not exist, the endpoints return:

{
  "error": "Invalid path"
}

Status code: 400

File Not Found

If the file does not exist, the endpoints return:

{
  "error": "File not found"
}

Status code: 404

Missing Parameters

If required parameters are missing, the endpoints return:

{
  "error": "Path is required"
}

Status code: 400

Edit Not Found

If the old text is not found in the file, the endpoints return:

{
  "error": "Old text not found in file"
}

Status code: 400

Service Errors

If a service encounters an error, the endpoints return:

{
  "error": "Error message"
}

Status code: 500

Security

  • Authentication: Editor endpoints require authentication
  • Authorization: Only authorized users can access file operations
  • Path Traversal: File paths are validated to prevent path traversal attacks
  • File Access: File access is restricted to workspace directory
  • Edit Validation: Old text is validated before applying edits
  • Directory Creation: Parent directory creation is restricted to workspace

Performance Considerations

  • Large Files: Reading large files may be slow
  • File Count: Listing directories with many files may be slow
  • Edit Operations: Text replacement operations scan entire file
  • Caching: Consider caching file contents for better performance
  • Batch Operations: Consider batch operations for multiple file edits

Limitations

  • Binary Files: Binary file editing is not supported
  • Large Files: File size limits may apply
  • Concurrent Edits: No support for concurrent editing
  • File Locking: No file locking mechanism
  • Undo/Redo: No undo/redo functionality
  • Diff View: No diff view for changes

Future Enhancements

  • Add binary file support
  • Implement file locking mechanism
  • Add undo/redo functionality
  • Implement diff view for changes
  • Support for concurrent editing
  • Add file versioning integration
  • Implement file search and replace
  • Add file compression support
  • Implement file upload/download
  • Support for multiple file editing
  • Add file sharing capabilities
  • Implement file collaboration features
  • Web Interface
  • Web Interface File Browser
  • Web Interface Code Editor
  • REST API
  • Workspace System
  • File Browser

Source: wiki/editor-system.md · rendered 2026-11-10