OpenSumi Core Documentation

repository·main·Indexed 25 days ago

https://github.com/opensumi/core

A framework for building AI-native IDE products across Cloud, Desktop (Electron), and Web environments. It provides tools for collaborative editing, remote service communication via backService and RemoteService patterns, UI overlay management, and a flexible icon system using Codicons and IconfontCN. The framework includes specialized utilities like GDataStore for state management in remote services and FileDecorationsService for managing file-based UI decorations.

Tokens
91.4K
Snippets
144
Records
603
Agent score
86%

What's inside OpenSumi

  1. Collaboration Module platform support and limitations

    main

    The Collaboration Module has specific environmental requirements and functional constraints:

    Supported Platforms

    • Cloud IDE scenarios only: Requires both a Browser and a Node.js application component.
    • Unsupported: Browser-only environments and Electron platforms are currently not supported.

    Functional Limitations

    • Editor focus: Collaborative editing is currently limited to the IDE editor portion only.
    • External file changes: The module does not currently handle file modifications made outside of the IDE editor (e.g., git pull or modifications via external software).
  2. Understand OpenSumi Editor Tab states and transitions

    main

    The OpenSumi editor uses several distinct tab states and organizational structures to manage user workflows. Understanding these is key to managing editor sessions and tab behavior:

    Tab States

    • Preview Tab: A provisional tab that is subject to being replaced when a new resource is opened in preview mode.
    • Keep Open: A state transition that converts a Preview Tab into an ordinary non-preview tab. This prevents subsequent preview openings from replacing the current tab. Note that Keep Open is distinct from pinning.
    • Pinned Tab: A tab explicitly fixed by the user within a specific Editor Group. Pinned tabs are restored with the group's session state, appear in the Pinned Region, and are protected from ordinary single-tab or bulk close actions (though they remain explicitly closeable). Pinning a Preview Tab also triggers Keep Open, but unpinning does not restore the preview state.

    Organizational Concepts

    • Editor Group: An independently arranged collection of editor tabs. A single resource can exist in multiple Editor Groups with different tab states in each.
    • Pinned Region: The leading section of an Editor Group's tab bar where all Pinned Tabs for that specific group are located.
  3. Understand the Extension Module Directory Structure

    main

    The Extension module is organized into several key services and layers to manage plugin lifecycles, command execution, and view bindings across different environments (browser, worker, and node):

    • Lifecycle & Management:

      • activation.service.ts: Manages and emits activateEvents.
      • extension-instance-management.ts: Aggregates and queries plugin instance data.
      • extension-management.service.ts: Provides low-level plugin management logic.
      • extension-node.service.ts: Manages plugin contribution point activation and process lifecycle for the node layer.
      • extension-worker.service.ts: Manages plugin contribution point activation and process lifecycle for the worker layer.
      • extension-view.service.ts: Manages plugin contribution points for the browser view layer and handles proxy binding with worker/node layers.
      • extension.service.ts: Provides the complete logic for plugin process activation.
    • Execution & Environment:

      • extension-command-management.ts: Provides the command execution environment for the plugin process and manages environment executors.
      • extension.contribution.ts: Provides contribution point logic for the plugin process.
      • extension.ts: Represents the Extension Instance.
    • API Layers:

      • sumi/: Node-layer APIs and contribution points for Sumi.
      • sumi-browser/: Browser-layer APIs and contribution points for Sumi.
      • vscode/: Node-layer APIs and contribution points for VSCode (includes builtin-commands.ts for command namespaces).
  4. Understand the Remote Service concept

    main

    In OpenSumi, a RemoteService is a specialized service designed exclusively for communication with the frontend. It acts similarly to a Controller in a layered architecture (Controller-Service-DAO), handling validation, logic, and scheduling for external requests.

    Key Principles of Remote Services:

    1. 1-to-1 Communication: They facilitate direct communication between the frontend and backend.
    2. Lifecycle Management: A RemoteService is instantiated only after a communication connection is established and cannot be re-instantiated.
    3. Naming Convention: It is recommended that all RemoteService classes end with the suffix RemoteService.
    4. Isolation: Backend services (other than the frontend) are prohibited from referencing a RemoteService via @Autowired to prevent state inconsistency and dependency issues.
  5. Understand the Agentic Layout architecture

    main

    OpenSumi's Agentic Layout is integrated directly into the existing workspace-local workbench rather than being a standalone application. The layout combines the following components into a single desktop workbench:

    • Agent Task List: For managing agent-specific tasks.
    • ACP Main Conversation Area: The primary interface for interacting with the AI.
    • Editor: The standard code/text editor.
    • File Tree: The workspace file explorer.
  6. Understand the Model Control Protocol (MCP) Architecture

    main

    The Model Control Protocol (MCP) is an integration layer that exposes IDE functionalities to AI models through a standardized interface. It allows AI models to interact with the IDE environment, manipulate files, and execute various operations.

    Core Components

    • MCPServerManager: Manages multiple MCP servers, handles tool registration/invocation, and maintains server lifecycles (start/stop). Each browser tab has its own instance.
    • MCPServerRegistry: Acts as the frontend proxy for MCP. It registers and manages MCP tools and handles tool calls.
    • SumiMCPServerBackend: The backend service connecting the browser and Node.js layers. It manages tool registration/invocation and handles communication between frontend and backend.
    • ToolInvocationRegistry: A registry of all available function calls provided to the Agent. It maps tool IDs to implementations and supports registration, retrieval, and unregistration.
    • ToolInvocationRegistryManager: Manages multiple ToolInvocationRegistry instances, ensuring isolation between different client contexts (each instance is associated with a specific clientId).
  7. Understand OpenSumi RPC Connection Protocol

    main
    OpenSumi RPC Connection is a transport-agnostic protocol inspired by the JSON-RPC specification. It is designed to work across various environments, including same-process communication, sockets, HTTP, and other message-passing systems. Instead of JSON, it uses the FURY binary format for high-performance serialization and parsing, making it more efficient for high-performance RPC than text-based formats.
  8. Understand Agentic Layout and ACP Agents

    main

    OpenSumi's Agentic Layout is a workspace-local mode that integrates an Agent Task List and an ACP Main Conversation Area into the ACP Chat Slot alongside the standard editor and file tree.

    All agents in this layout must be ACP Agents (Agent implementation communicating via the Agent Client Protocol).

    Key constraints:

    • Agentic Layout Isolation: Changes to the layout must not alter the IDE Layout lifecycle or Workspace behavior.
    • Shared Workspace Concurrency: Multiple Agent Tasks can run for the same Workspace Target in separate ACP Threads, sharing the same backing directory. Agents are responsible for their own coordination; the platform does not isolate or detect conflicts.
  9. Handle MCP tool errors

    main

    When a tool encounters an error, it should return a standardized error response so the AI model can understand the failure. The response must include isError: true and a content array containing the error message.

    {
      content: [{
        type: 'text',
        text: 'Error: <error message>'
      }],
      isError: true
    }
  10. Understand the Editor opening process

    main

    Opening a tab in the IDE follows a specific lifecycle managed by the WorkbenchEditorService:

    1. Initiation: Call WorkbenchEditorService.open(uri) with a target URI (e.g., file://path/to/file.ts).
    2. Resource Resolution: The URI is converted into an IResource via a registered IResourceProvider. This resource provides metadata like the tab name and icon.
    3. Tab Creation: An IResource is used to create the tab in the UI, displaying its name and icon.
    4. View Resolution: The system determines how to display the resource (e.g., as code, diff, or a React component) by querying the EditorComponentRegistry.
    5. Rendering: The selected view type is rendered in the editor main area.