дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
Closing a remote window (SSH, WSL, Dev Containers) used to end openidea-server --stdio and tear down terminals, runs (running their stop commands), indexing and agent turns. openidea-server --attach now connects through a detached per-project daemon (private 0700 run dir, owner check, flock) that keeps them alive across disconnects; reopening reattaches terminals with bounded scrollback and OSC state, runs and agent turns, and restores remote editor tabs, tool windows and plugin views. The close dialog offers Keep Backend Running / Stop Backend; Stop Remote Backend shuts the daemon down on demand. A disconnected backend with no live work exits after an idle timeout (3 hours by default; presets, custom or Never in Settings › Tools › Remote Development, host override wins). The socket is keyed by project, so a new build replaces an idle backend of another build and reports a busy one; a window taken over by another shows that instead of a dropped connection. Clean documents are released on disconnect while dirty buffers keep the backend alive. Also: a plugin-owned PTY keeps its exit hook across reattach (reattach only rebinds the forwarding sink), and a recent project clicked again while it is still opening joins that attempt instead of connecting twice (a double click made the second attach take over and fail the first). Co-authored-by: dengliu <[email protected]>
110 рядки
10 KiB
Plaintext
110 рядки
10 KiB
Plaintext
---
|
||
title: "Remote development"
|
||
description: "How a desktop window works on a project on another machine: openidea-server, its JSON-RPC protocol over SSH, WSL or docker exec, and command routing in the frontend."
|
||
---
|
||
|
||
In remote development a window's project lives on another machine (an SSH host, a WSL distribution or a dev container). The UI stays on the desktop; the backend for that project — the same `ide-host` `Host` the desktop uses — runs on the remote machine as `openidea-server`. For using it, see [Remote development over SSH](/en/guide/remote/ssh).
|
||
|
||
<Note>
|
||
Two crates have "remote" in their name but are different things. **Remote development** is `ide-host` (`rpc.rs`, the
|
||
`openidea-server` binary) plus the client in `src-tauri/src/remote_dev.rs`. **`ide-remote`** is SFTP deployment and
|
||
run targets (running a configuration over SSH or in Docker from a local project).
|
||
</Note>
|
||
|
||
## Pieces
|
||
|
||
```mermaid
|
||
flowchart LR
|
||
subgraph Desktop
|
||
UI["frontend<br/>platform/remote.ts"] -- "remote_invoke" --> RD["src-tauri remote_dev.rs<br/>Connection"]
|
||
end
|
||
RD -- "JSON-RPC, Content-Length framing" --> T{"transport"}
|
||
T -- "SSH exec channel" --> S1["openidea-server --stdio"]
|
||
T -- "wsl.exe --exec" --> S2["openidea-server --stdio"]
|
||
T -- "docker exec -i" --> S3["openidea-server --stdio"]
|
||
S1 --> H["ide-host: Host<br/>projects, LSP, index, git,<br/>terminals, runs, debugger, plugins"]
|
||
```
|
||
|
||
| Piece | Where |
|
||
| --------------------------------- | ----------------------------------------------------------------------------- |
|
||
| Server binary | `crates/ide-host/src/bin/server.rs` (`openidea-server`) |
|
||
| Persistent daemon and attach | `crates/ide-host/src/daemon.rs` (`openidea-server --attach` / `--daemon`) |
|
||
| Protocol and dispatcher | `crates/ide-host/src/rpc.rs` |
|
||
| Client: connect, install, forward | `src-tauri/src/remote_dev.rs` |
|
||
| WSL and dev container transports | `src-tauri/src/remote_wsl.rs`, `src-tauri/src/remote_container.rs` |
|
||
| Port relay inside a container | `crates/ide-host/src/relay.rs` (`openidea-server --connect`) |
|
||
| Frontend routing | `src/platform/remote.ts`, hooked into `invoke` by `src/platform/tauriCore.ts` |
|
||
| UI (File › Remote Development…) | `src/features/remote-dev/` |
|
||
|
||
## The server
|
||
|
||
```text
|
||
openidea-server --stdio | --attach <project-path> | --mcp-stdio [--project <path>] | --connect <host> <port> | --version
|
||
```
|
||
|
||
- `--attach <project-path>` bridges stdin/stdout to a detached daemon on a `0600` Unix socket in a `0700` directory. The socket key is stable across builds. The relay checks the daemon's build before attaching; a different build can replace it only when no window, live workload, or unsaved document remains. Idle or explicit shutdown keeps the socket bound until cleanup is complete.
|
||
- `--stdio` serves a single desktop client directly over stdin/stdout and exits on EOF. stdout carries the protocol, so logs go to stderr (filter with `OPENIDEA_LOG`).
|
||
- Its state lives under `OPENIDEA_SERVER_HOME` (default `~/.openidea`), in `config/` and `data/`. Language definitions can be added in `config/languages/`.
|
||
- An SSH exec channel gets a minimal environment, so on every start the server takes the login shell's environment and adds the IDE-managed tools directory to `PATH`.
|
||
- `--version` prints the app version and the protocol version.
|
||
|
||
### Installing it on the remote machine
|
||
|
||
The desktop picks the server binary for the remote OS and architecture (from `uname -sm`): `OPENIDEA_SERVER_BINARY` if set, then the one next to the app when the platforms match; otherwise the release build of this version for that platform, downloaded once into `<data dir>/server/<version>/<os>-<arch>/`. Offline, it falls back to a build of this version already on the host, then to the unversioned `<data dir>/server/<os>-<arch>/openidea-server`. The server reports its version in `initialize`; a command missing on a server of another version fails with both versions named. It uploads the binary into `~/.openidea/server/` on the remote host, one folder per version, keyed by a content hash, and removes other builds of that version. CI keeps a static Linux (musl) build working.
|
||
|
||
## The protocol
|
||
|
||
JSON-RPC 2.0 with `Content-Length` framing (`ide-jsonrpc`), over the server's stdio:
|
||
|
||
| Message | Direction | Payload |
|
||
| ----------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
| request `initialize` | client → server | `{ version }` → `ServerInfo { version, protocol, os, arch, home }` |
|
||
| request `commands` | client → server | the names of the commands the server answers |
|
||
| request `invoke` | client → server | `{ window, cmd, args }` → the command's result. `args` as the desktop command takes them (camelCase); a streaming argument is `{ "$channel": <id> }` |
|
||
| notification `event` | server → client | `{ window, event }`: an `IdeEvent` for that window, or for every window when `window` is null |
|
||
| notification `channel` | server → client | `{ id, data }`: one value of a streaming argument |
|
||
| notification `plugin` | server → client | `{ window, event }` from code plugins of the remote project |
|
||
| request `plugin_secret` | server → client | `{ plugin, name }` → `string` or `null`: a secret from the desktop's keychain |
|
||
|
||
The protocol version is `PROTOCOL_VERSION` in `rpc.rs`; the desktop refuses a server that speaks another one. Change it when an existing command's argument or result changes shape. A binary argument is an `IpcBytes` (a base64 string in JSON, `string` in the bindings), never a `Vec<u8>`, which is an array of numbers about 3.6 times the size. Errors are `IdeError`s carried as JSON in the JSON-RPC error message, so the frontend sees the same `kind` / `message` as for a local command.
|
||
|
||
## Routing commands
|
||
|
||
The frontend doesn't know whether a window is remote. Features call `commands.*` as usual; the routing happens below the generated bindings:
|
||
|
||
1. `src/platform/tauriCore.ts` is what `@tauri-apps/api/core` resolves to (a Vite alias). Its `invoke` asks the installed route first.
|
||
2. In a remote window, `src/platform/remote.ts` installs a route that sends the commands listed in the session's `commands` to `remote_invoke`, and runs everything else locally.
|
||
3. `remote_invoke` replaces each `Channel` argument with `{ "$channel": id }`, forwards the call as an `invoke` request, and delivers `channel` notifications back to the right `Channel`. `event` notifications are re-emitted to the window through the normal event sink.
|
||
|
||
A few commands are always local even if the server knows them: `open_project` and `close_project` (opening a local folder leaves the remote one; closing drops the connection), system font listing, and client UI settings. Client settings (keymap, appearance, editor fonts and colours…) are listed in `src/platform/clientSettings.ts`; a global tooling setting is applied on both sides.
|
||
|
||
### What runs where
|
||
|
||
| On the remote machine | On the desktop |
|
||
| --------------------------------------------------------- | ------------------------------------ |
|
||
| The project: files, documents, settings | Windows, menus, the webview |
|
||
| Language servers, index, search | Client UI settings, keymaps, themes |
|
||
| Git, terminals, runs, debug adapters, built-in MCP server | The SSH connection and port forwards |
|
||
| Code plugins of the project, their processes and fetches | Plugin secrets (keychain) |
|
||
|
||
## Port forwarding
|
||
|
||
Forwarded ports go through the SSH connection. In a dev container, each connection to a forwarded port runs `openidea-server --connect localhost <port>` inside the container (via `docker exec`) and pipes the connection through its stdin/stdout, so the container's network is reachable the same way on every Docker setup.
|
||
|
||
## Trust
|
||
|
||
Restricted mode works the same in remote windows: before forwarding a command whose trust class isn't `always`, the desktop checks its own decision about the remote project, and the server authorizes every `invoke` again with `Host::authorize` and the class the command declares. For a dev container of a folder the user already trusts, the desktop starts the server with that project folder marked trusted (`OPENIDEA_TRUSTED_ROOT`, never persisted).
|
||
|
||
The WSL and container transports run programs with arguments directly (`wsl.exe --exec`, `docker exec`); only fixed scripts reach `sh -c`, and every variable value is passed as a positional argument.
|
||
|
||
## Making a command work remotely
|
||
|
||
Declare it with `#[command(trust = …)]` on its implementation in `ide-host::ops::<domain>` and list it in that module's `domain!` (see [Commands](/en/contribute/architecture/ipc#commands)). The server's `Dispatcher` gets its handler, and the desktop routes it, from that one declaration. The desktop's list of routed commands comes from its own build, never from the server, so a server cannot move a command to the desktop.
|
||
|
||
A command declared with `#[desktop_command]` in `src-tauri` runs on the desktop even in a remote window, which is wrong for anything that touches the project.
|
||
|
||
## Testing
|
||
|
||
- `crates/ide-host/tests/rpc.rs`, `remote_env.rs`, `remote_plugins.rs`: the protocol and server behaviour.
|
||
- `smoke/server.ts` starts a real `openidea-server --stdio` and speaks the protocol to it; `smoke/desktop.ts` gives the frontend's modules a Tauri runtime whose commands go to that server through the remote-development route. The run and debug smoke tests use it (see [Smoke tests](/en/contribute/testing/smoke)).
|