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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The user-visible changes of canoP, by version (see `CONTRIBUTING.md` for the ver

## Unreleased

- canoP studio with VS Code Remote-SSH, where code-server is not allowed: the user guide describes the
installation, the canoP icon and Claude Code (proxy of the Claude API); `open_studio` of the MCP
bridge recognises a Remote-SSH window and points to the canoP icon or the Ports panel of VS Code
instead of an ssh tunnel.
- canoP studio in English or in French: a FR/EN switch in the top bar, saved in the settings. New
installations start in English; studios set up before keep French.
- Tutorial of canoP studio in the documentation: the build, a run of the blast example, and a
Expand Down
45 changes: 42 additions & 3 deletions docs/user-guide/studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,45 @@ tools/start-code-server.sh

It starts code-server in the background unless it already runs, and prints its address again.

### In VS Code with Remote-SSH

Where code-server is not allowed but VS Code Remote-SSH is (for example on some national computing
centres), use VS Code on your computer with its Remote-SSH extension. VS Code forwards the ports of
the node through its own connection: no `ssh -L` tunnel is needed.

1. Connect the window to one fixed login node (`<host>01`, not an alias that picks one of several):
the studio, its builds and Claude Code run on the node of the window. When ssh keys are not
allowed, a `ControlMaster` in `~/.ssh/config` of your computer asks the password once.
2. In a terminal of the window, once:

```bash
tools/trame/canop-studio --setup # Python environment of the studio (pip: needs PyPI)
tools/trame/canop-studio --install-vscode # canoP icon in the activity bar
```

then *Developer: Reload Window*. Behind the web proxy of a centre, give it to pip first
(`export https_proxy=http://<proxy>:<port>`).
3. The canoP icon starts the studio and opens it in the Simple Browser, at the address that VS Code
forwards. VS Code forwards the port of the studio on the node (8090 or the next free one) to the
same port of your computer when it is free, else to another one, which changes from one session to
the next: the *Ports* panel shows it and opens the studio in the browser of your computer. Keep the
path and the key of the address (`/index.html?secret=...`): without the key the page does not
connect.

Claude Code: install its VS Code extension in the Remote-SSH window. It runs on the node, reads the
`.mcp.json` of the repository and drives the studio of that node with its MCP tools; `open_studio`
points to the canoP icon or to the *Ports* panel. The node must reach the Claude API over HTTPS. Behind a web
proxy, check that it lets the API through, then give it to Claude Code in `~/.claude/settings.json`
on the node:

```bash
curl -sI -x http://<proxy>:<port> https://api.anthropic.com | head -1
```

```json
{ "env": { "HTTPS_PROXY": "http://<proxy>:<port>" } }
```

### From a terminal

```bash
Expand All @@ -91,9 +130,9 @@ via code-server: http://127.0.0.1:8080/proxy/8090/index.html?secret=...
direct: http://localhost:8090/index.html?secret=...
```

From code-server on the same node, open the first one. Otherwise open an ssh tunnel
(`ssh -L 8090:localhost:8090 <login node>`) and the second one. The server keeps running without a
browser; Ctrl-C stops it.
From code-server on the same node, open the first one. In VS Code with Remote-SSH, open the second
one at the local port that VS Code forwards to it (the *Ports* panel). Otherwise open an ssh tunnel (`ssh -L 8090:localhost:8090 <login
node>`) and the second one. The server keeps running without a browser; Ctrl-C stops it.

### VS Code button

Expand Down
3 changes: 3 additions & 0 deletions tools/trame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ direct: http://localhost:8090/index.html?secret=...
application, and asks for its own login first. This only works when the
application runs on the node of code-server (one login node of several): start it
from a code-server terminal. The address is only printed in that case.
- In VS Code with Remote-SSH (where code-server is not allowed), use the
canoP icon (below), or the second address at the local port that VS Code
forwards to it (Ports panel; it may differ from the port of the node).
- Otherwise, open an ssh tunnel from your machine, then open the second
address:

Expand Down
26 changes: 26 additions & 0 deletions tools/trame/canop_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fcntl
import json
import os
import re
import signal
import socket
import subprocess
Expand All @@ -28,6 +29,31 @@
else os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "canop-studio"))
HOST = socket.gethostname()
START_TIMEOUT = 120 # seconds, for the studio to load VTK and open its ports
# Directory of the server that VS Code Remote-SSH (or a fork of VS Code) runs on the node
_REMOTE_SERVER = re.compile(r"/\.(vscode-server|vscode-server-insiders|cursor-server|windsurf-server)/")


def vscode_remote(pid=None):
"""True when the process runs under the server of VS Code Remote-SSH: the program of one of its ancestors
is in ~/.vscode-server/ (or that of a fork of VS Code), as the node of the server and of its extension
hosts. VS Code then forwards the ports of the node to the computer of the user: the studio opens at its
direct address, without an ssh tunnel. Only the programs are read, not their arguments.
"""
pid = os.getpid() if pid is None else pid
for _ in range(64):
try:
with open("/proc/%d/cmdline" % pid, "rb") as fd:
program = fd.read().split(b"\0", 1)[0].decode(errors="replace")
with open("/proc/%d/stat" % pid, encoding="utf-8") as fd:
ppid = int(fd.read().rsplit(")", 1)[1].split()[1])
except (OSError, ValueError, IndexError): # no /proc (macOS), or the process is gone
return False
if _REMOTE_SERVER.search(program):
return True
if ppid <= 1:
return False
pid = ppid
return False


def endpoint_file():
Expand Down
33 changes: 24 additions & 9 deletions tools/trame/canop_mcp_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@
import canop_assistant as studio # noqa: E402 (tool list only: no trame import)

from canop_launch import (CONFIG_DIR, HOST, StudioError, _studio_process, endpoint, ensure_studio, # noqa: E402
terminate_studio)
terminate_studio, vscode_remote)

CALL_TIMEOUT = 2000 # seconds; wait_for_job may wait up to 1800
PROTOCOL_VERSION = "2025-06-18" # answered when the client asks for none


def _addresses(info):
"""Addresses of the studio, for the user: through code-server and through an ssh tunnel."""
def _addresses(info, remote=None):
"""Addresses of the studio, for the user: through code-server, then direct.

The direct address opens through VS Code when Claude Code runs in a window of VS Code Remote-SSH
(VS Code forwards the port), otherwise through an ssh tunnel.
"""
remote = vscode_remote() if remote is None else remote
lines = []
if info.get("url_code_server"):
lines.append("via code-server (à ouvrir dans VS Code : Ctrl+Shift+P > Simple Browser: Show) : "
+ info["url_code_server"])
lines.append("en direct (tunnel ssh -L %d:localhost:%d %s) : %s"
% (info["port"], info["port"], HOST, info["url_direct"]))
if remote:
lines.append("dans VS Code Remote-SSH : l'icône canoP de la barre d'activité ; ou l'onglet Ports, où VS Code "
"redirige le port %d vers un port de l'ordinateur qui peut différer (garder le chemin et la "
"clé) : %s" % (info["port"], info["url_direct"]))
else:
lines.append("en direct (tunnel ssh -L %d:localhost:%d %s) : %s"
% (info["port"], info["port"], HOST, info["url_direct"]))
return lines


Expand Down Expand Up @@ -78,9 +88,11 @@ def stop_studio(args):

LOCAL_TOOLS = [
("open_studio",
"Start canoP studio on this node if it is not running, and return the addresses where the user sees it "
"(give them the code-server one: they open it in VS Code with 'Simple Browser: Show'). Call it first when "
"another tool reports that the studio is not running.",
"Start canoP studio on this node if it is not running, and return the addresses where the user sees it: "
"through code-server (they open it in VS Code with 'Simple Browser: Show'), and the direct one, either "
"through VS Code Remote-SSH (the canoP icon of the activity bar, or the Ports panel: VS Code forwards the "
"port to a local port that may differ) or through an ssh tunnel. Call it first when another tool reports "
"that the studio is not running.",
studio._obj(), open_studio),
("stop_studio", "Stop canoP studio on this node (builds and runs already started keep going).",
studio._obj(), stop_studio),
Expand Down Expand Up @@ -176,7 +188,10 @@ def _instructions():
"""Server instructions: those of the studio assistant, and how to open the studio."""
return studio.SYSTEM_PROMPT + (
"\n\nThe studio is a separate web application. If a tool says it is not running, call open_studio and "
"give the user the code-server address, to open in VS Code with 'Simple Browser: Show'.")
"give the user the address it returns for their setup: the code-server one, to open in VS Code with "
"'Simple Browser: Show'; in VS Code Remote-SSH, the canoP icon of the activity bar, or the Ports panel "
"(VS Code forwards the port to a local port that may differ: keep the path and the key); otherwise the "
"direct address through an ssh tunnel.")


def _call_tool(msg_id, params):
Expand Down
Loading