Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions adr/0002-vscode-extensions-in-the-ide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ADR 0002: Run VS Code extensions in the Code-XR IDE with our own extension host and Open VSX

- **Status:** Accepted
- **Date:** 2026-11-27
- **Deciders:** Adrián Montes Linares (@aMonteSl)
- **Context:** ADR 0001 (Electron + Monaco), the IDE epics #11 and #163, and the extensions epic (stream `ide-extensions`)
- **Design notes:** [`docs/ide/extensions.md`](../docs/ide/extensions.md)

## Context

The Code-XR IDE is a custom Electron + Monaco workbench (ADR 0001): about 30,000 lines of hand-written TypeScript with its own explorer, tabs, Source Control, terminal, Problems, Output, settings, command palette, LSP bridge, debugger and AI agent hub. People coming from VS Code expect their extensions: a colour theme, a language they need highlighted, a linter, a formatter. And Code-XR itself is a VS Code extension: running it unchanged inside the IDE would prove the IDE is a real host and would keep one code base for both.

Three questions must be answered:

1. **How do extensions run?** A VS Code extension is a Node.js module that `require('vscode')` and calls an API of about 700 functions and classes, plus a `package.json` whose `contributes` section declares themes, grammars, languages, snippets, commands, menus, views, settings and keybindings without any code.
2. **Where do they come from?** The Visual Studio Marketplace is the default source in VS Code.
3. **What is legal and safe?**

## Options considered

### A. Fork Code-OSS, or embed VS Code's workbench with `@codingame/monaco-vscode-api`

`monaco-vscode-api` (MIT) re-packages VS Code's own services on top of Monaco, including the real extension host (in a worker or a Node process) and the real workbench parts. It is the route with the highest compatibility: the API is VS Code's own code. OpenVSCode Server, code-server, VSCodium and Eclipse Che (Che-Code) reach the same result by forking VS Code outright.

Rejected for now. Its services take over exactly what the IDE has built by hand and is still building in parallel (layout, theming, keybindings, views, the editor model and its tabs); adopting it means replacing the workbench, not adding a feature. It pins the IDE to Monaco builds that follow VS Code's monthly releases, and ADR 0001 already rejected a fork for its maintenance cost. It stays the fallback if the coverage gaps of option C turn out to dominate (see "Revisit when").

### B. Eclipse Theia's plugin system

Theia (EPL-2.0) implements the VS Code API in its own plugin host. Its implementation cannot be lifted out without Theia's dependency-injection framework, which ADR 0001 rejected, and its coverage is still partial in the areas that matter to Code-XR (webviews, tree views).

### C. Our own extension host, Theia-style, scoped to what people use (chosen)

Follow VS Code's process model with our own code:

- **Declarative contributions are handled by the workbench itself**, with no extension code running: colour themes (VS Code theme JSON turned into a Monaco theme and the workbench's colour tokens), TextMate grammars (`vscode-textmate` + `vscode-oniguruma`, both MIT, the libraries VS Code uses), languages and their language configuration, snippets, and the settings schema. This is most of what people install by count: themes and language support.
- **Extension code runs in a separate Node process per window**, the *extension host*, started with Electron's own Node (`ELECTRON_RUN_AS_NODE`), like the language servers (#21). It intercepts `require('vscode')` and hands each extension an API object of its own. Extensions never run in the renderer and never get the renderer's privileges; a crash or a hung extension never takes the window down.
- **The API is implemented incrementally**, by what popular extensions and `vscode-languageclient` call: commands, messages and quick picks, output channels, status bar, configuration, text documents and their events, diagnostics, language features bridged to Monaco providers, workspace file system and file watchers, tree views and webviews. **Anything not implemented degrades instead of throwing**: unknown `register*` functions return a no-op `Disposable`, and every such call is logged once per extension in an *Extensions* channel of the Output panel. That log is the coverage measurement that decides what to implement next.

Trade-offs accepted: compatibility is partial and has to be measured per extension; proposed APIs, notebooks, the debug API, authentication providers, custom editors and remote development are out of scope at first; a language pack only translates VS Code's own UI strings, which the IDE does not use, so it installs but changes nothing visible.

## Marketplace: Open VSX, never the Visual Studio Marketplace

The [Visual Studio Marketplace Terms of Use](https://cdn.vsassets.io/v/M190_20210811.1/_content/Microsoft-Visual-Studio-Marketplace-Terms-of-Use.pdf) allow installing Marketplace offerings only in Visual Studio products and services. The IDE therefore uses **[Open VSX](https://open-vsx.org)**, the vendor-neutral registry run by the Eclipse Foundation, which VSCodium, Theia, Gitpod, Eclipse Che, code-server and Cursor use. Its REST API is public and needs no key (`/api/-/search`, `/api/{namespace}/{name}`, the `.vsix` and its `sha256`). The registry URL is a setting, so a company can point the IDE at its own Open VSX instance. A `.vsix` file can also be installed from disk.

Consequences: some Microsoft extensions are not on Open VSX and their licences forbid use outside VS Code (Pylance, C/C++, C# Dev Kit, Remote Development, Live Share, GitHub Copilot). The IDE neither works around this nor downloads them from Microsoft. Their open-source counterparts are on Open VSX (basedpyright, clangd, etc.).

## Licensing

- The IDE is GPL-3.0; the extension host and the API shim are our own code. Libraries used: `vscode-textmate`, `vscode-oniguruma`, `vscode-uri` (MIT). The API typings (`@types/vscode`) are MIT and only used to check the shim.
- Extensions are not shipped with the IDE: the person installs them at run time, each under its own licence, which the Extensions view shows before installing.

## Security

An extension is arbitrary code that runs with the person's rights, as in VS Code. The IDE does not pretend otherwise, and applies the same rules VS Code does, plus what its own baseline (README "Security baseline") requires:

- **Nothing is downloaded unless the person asks** (searching or installing in the Extensions view). The `.vsix` is checked against the `sha256` the registry publishes, and unpacked with path checks (no `..`, no absolute paths, no links) into `<userData>/extensions/`.
- **Installing shows who publishes it** (Open VSX's verified-publisher flag), its licence, and that it will run code with the person's rights.
- **Workspace trust (#177):** in Restricted Mode only extensions that declare `capabilities.untrustedWorkspaces.supported` are activated, as in VS Code. Declarative contributions (themes, grammars) still apply.
- **The renderer stays sandboxed.** Extension code never runs in it. Webviews of extensions run in sandboxed iframes from their own origin with their own CSP, and talk to the host only through `postMessage` relayed by the main process. The renderer CSP gains `'wasm-unsafe-eval'` only, for the Oniguruma regex engine of TextMate grammars (VS Code does the same); `eval` stays forbidden.
- Every extension can be disabled or uninstalled, and the host can be restarted, from the Extensions view.

## Revisit when

- The *Extensions* coverage log shows that the extensions people actually use fail on API areas too large to write by hand (notebooks, debug, custom editors), or
- `monaco-vscode-api` can be adopted per service without replacing the workbench.

Then option A becomes the better trade, and this host is retired.
1 change: 1 addition & 0 deletions adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Decisions that shape Code-XR beyond a single feature, one file per decision, num
| # | Decision | Status |
|---|---|---|
| [0001](0001-code-xr-ide-platform.md) | Build the Code-XR IDE on Electron + Monaco | Accepted |
| [0002](0002-vscode-extensions-in-the-ide.md) | Run VS Code extensions in the IDE with our own extension host and Open VSX | Accepted |
6 changes: 6 additions & 0 deletions apps/ide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Following Electron's [security checklist](https://www.electronjs.org/docs/latest
| Git runs without a shell, on paths checked inside the open folder; discard asks natively and trashes untracked files | `src/main/git/` (`runGit`, `resolveGitPath`, `gitIpc.ts`) | Unit tests (`..`, absolute paths, symlinks out, globs, option-like branch names); smoke refuses `git.headContent('../package.json')`. |
| The renderer cannot start or address a language server: it names documents by `codexr-file:` URI inside the open folder and sends only allow-listed requests with rebuilt parameters | `src/main/lsp/` (`lspUri.ts`, `lspProtocol.ts`), `LSP_REQUEST_METHODS` in `src/shared/lsp.ts` | Unit tests (`test/lsp.test.ts`: `..`, encoded separators, other schemes, refused methods, forged completion data). |
| No network request unless the person asks: the update check runs from Help > Check for Updates…, or at start-up only if `update.checkOnStartup` is turned on (off by default); it reads the public GitHub releases list, downloads nothing and only opens the release page in the browser | `src/main/updates/` (`updateRelease.ts` pure, `updateCheck.ts`) | Unit tests (`test/updateCheck.test.ts`: tags, drafts, pre-releases, versions); never run in the smoke run. |
| Extensions (#251) are unpacked only from checked archives: entries under `extension/` only, no `..`, absolute paths, drive letters or links, size limits; an Open VSX download must match the registry's SHA-256; a native dialog shows publisher, verification, licence and whether it runs code before anything is installed; nothing goes online unless the person searches or installs | `src/main/extensions/` (`vsix.ts`, `openVsx.ts`, `extensionsService.ts`) | Unit tests (`test/extensions.test.ts`: zip-slip, symlink and garbage archives, wrong and missing checksums, http downloads, tampered `extensions.json`). |
| The renderer may compile WebAssembly (`'wasm-unsafe-eval'`) for the TextMate regex engine of extension grammars (#258); `eval` stays blocked | `buildContentSecurityPolicy` | Unit tests; smoke checks `eval` throws. |
| The dev server URL is ignored in a packaged build | `src/main/index.ts` (`app.isPackaged`) | Code review. |

Running as root (containers, some CI images) requires `--no-sandbox`, which the scripts add only in that case. It turns off Chromium's OS-level sandbox and `app.enableSandbox()`; the per-window `sandbox: true` preference and its assertion stay.
Expand Down Expand Up @@ -356,6 +358,10 @@ The parsers (`statusParser.ts`, `blameParser.ts`) are pure and unit-tested on st
3. Register the handler in `src/main/ipc.ts` through `handle()`, which already rejects untrusted frames. Validate every argument: the renderer is untrusted.
4. Add a unit test for any pure logic, and extend the smoke probe if the capability is security-relevant.

## VS Code extensions (stream `ide-extensions`, epic #251)

The Extensions view (activity bar, puzzle icon, `Ctrl/Cmd+Shift+X`) installs VS Code extensions from **Open VSX** (never the Visual Studio Marketplace, whose terms only allow Microsoft products; ADR [0002](../../adr/0002-vscode-extensions-in-the-ide.md)) or from a `.vsix` file, and enables, disables and uninstalls them. Colour themes, languages, TextMate grammars and snippets apply at once; extensions with code run in the extension host (#259, in progress). Design, state and how to try it: [`docs/ide/extensions.md`](../../docs/ide/extensions.md).

## AI agent hub (stream `ai-agents`)

The Agents view (activity bar, speech-bubble icon) connects the IDE to LLM providers with the person's **own API keys**. There is no Code-XR server in between: every call goes straight from the main process to the provider, and nothing is sent until a provider is configured and used.
Expand Down
71 changes: 71 additions & 0 deletions apps/ide/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,77 @@ Usage in this package:

- Bundled into the renderer by Vite: sanitises the Markdown preview's HTML before it reaches the page (#179, `src/renderer/editor/markdownPreview.ts`). The same version Monaco already depends on.

## vscode-textmate (TextMate grammars of extensions)

- Project: `vscode-textmate` on npm, 9.3.2, by Microsoft Corporation
- Source: https://github.com/microsoft/vscode-textmate
- License: MIT

Usage in this package:

- Bundled into the renderer by Vite: tokenizes files with the TextMate grammars that VS Code extensions contribute (#258, `src/renderer/extensions/textmate.ts`).

## vscode-oniguruma (regular expressions of TextMate grammars)

- Project: `vscode-oniguruma` on npm, 2.0.1, by Microsoft Corporation; WebAssembly build of Oniguruma 6.9.5 by K.Kosako
- Source: https://github.com/microsoft/vscode-oniguruma, https://github.com/kkos/oniguruma
- License: MIT (bindings); BSD-2-Clause (Oniguruma)

Usage in this package:

- Bundled into the renderer by Vite, with its `onig.wasm` served from the app (#258). It is why the CSP allows `'wasm-unsafe-eval'`.

Oniguruma's licence text, as `vscode-oniguruma` ships it:

```
Oniguruma LICENSE
-----------------

Copyright (c) 2002-2020 K.Kosako <kkosako0@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
```

## yauzl (reading .vsix archives)

- Project: `yauzl` on npm, 3.4.0, by Josh Wolfe
- Source: https://github.com/thejoshwolfe/yauzl
- License: MIT

Usage in this package:

- Bundled into the main process by Vite: reads the `.vsix` (zip) files of extensions before they are unpacked (#254, `src/main/extensions/vsix.ts`).

## jsonc-parser (JSON with comments)

- Project: `jsonc-parser` on npm, 3.3.1, by Microsoft Corporation
- Source: https://github.com/microsoft/node-jsonc-parser
- License: MIT

Usage in this package:

- Bundled into the main process by Vite: reads extension manifests, colour themes, language configurations and snippets, which VS Code allows to contain comments (#254).

## PDF.js (PDF viewer)

- Project: `pdfjs-dist` on npm, 6.5.438, by Mozilla and the PDF.js contributors
Expand Down
9 changes: 8 additions & 1 deletion apps/ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@
},
"devDependencies": {
"@types/node": "^22.20.7",
"@types/vscode": "1.146.0",
"@types/yauzl": "3.4.0",
"@xterm/addon-fit": "0.11.0",
"@xterm/xterm": "6.0.0",
"dompurify": "3.4.15",
"electron": "^45.5.0",
"electron-builder": "26.18.1",
"jsonc-parser": "3.3.1",
"marked": "14.0.0",
"material-icon-theme": "^5.40.0",
"monaco-editor": "0.57.0",
"pdfjs-dist": "6.5.438",
"vite": "^8.3.8",
"vscode-jsonrpc": "9.0.3",
"vscode-languageserver-types": "3.18.4"
"vscode-languageserver-types": "3.18.4",
"vscode-oniguruma": "2.0.1",
"vscode-textmate": "9.3.2",
"vscode-uri": "3.2.0",
"yauzl": "3.4.0"
},
"dependencies": {
"node-pty": "1.2.0-beta.18",
Expand Down
Loading
Loading