From 5fc1c24ba414c3bf2cd66deede782af584e9b1ef Mon Sep 17 00:00:00 2001 From: "pascal.tremblin" Date: Tue, 1 Dec 2026 22:11:36 +0100 Subject: [PATCH] studio: canoP studio and Claude Code with VS Code Remote-SSH Where code-server is not allowed but VS Code Remote-SSH is (Adastra at CINES, for example), the studio works through the canoP icon: without code-server the VS Code extension asks VS Code to forward the port of the studio (asExternalUri). What was missing: - the user guide (and tools/trame/README.md) describes this setup: a fixed login node, canop-studio --setup and --install-vscode from a terminal of the window, the canoP icon and the Ports panel, Claude Code in the window (it runs on the node and finds the studio through .mcp.json), and the web proxy of the Claude API (HTTPS_PROXY in ~/.claude/settings.json); - open_studio of the MCP bridge gave the code-server address or an ssh -L tunnel. canop_launch.vscode_remote() recognises a Remote-SSH window: the program of an ancestor of the process is in ~/.vscode-server/ (or that of a fork of VS Code; the arguments are not read). The bridge then gives the canoP icon or the Ports panel of VS Code, which forwards the port of the studio to a local port that may differ (62863 in a test on Adastra); the server instructions and the description of open_studio say which address fits which setup. Tested: the detection is false under code-server and when the path is only in the arguments of an ancestor, true under a program of ~/.vscode-server/ and two levels below it. The bridge is restarted by Claude Code (/mcp): the studio itself does not need a restart. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +++ docs/user-guide/studio.md | 45 ++++++++++++++++++++++++++++++--- tools/trame/README.md | 3 +++ tools/trame/canop_launch.py | 26 +++++++++++++++++++ tools/trame/canop_mcp_bridge.py | 33 +++++++++++++++++------- 5 files changed, 99 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e8a30..dee015a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/user-guide/studio.md b/docs/user-guide/studio.md index 48e0cdd..ddae3bc 100644 --- a/docs/user-guide/studio.md +++ b/docs/user-guide/studio.md @@ -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 (`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://:`). +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://: https://api.anthropic.com | head -1 +``` + +```json +{ "env": { "HTTPS_PROXY": "http://:" } } +``` + ### From a terminal ```bash @@ -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 `) 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 `) and the second one. The server keeps running without a browser; Ctrl-C stops it. ### VS Code button diff --git a/tools/trame/README.md b/tools/trame/README.md index 753ca8d..3e59dd8 100644 --- a/tools/trame/README.md +++ b/tools/trame/README.md @@ -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: diff --git a/tools/trame/canop_launch.py b/tools/trame/canop_launch.py index c6ce5bf..eb43059 100644 --- a/tools/trame/canop_launch.py +++ b/tools/trame/canop_launch.py @@ -12,6 +12,7 @@ import fcntl import json import os +import re import signal import socket import subprocess @@ -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(): diff --git a/tools/trame/canop_mcp_bridge.py b/tools/trame/canop_mcp_bridge.py index 7e5828a..005c56f 100644 --- a/tools/trame/canop_mcp_bridge.py +++ b/tools/trame/canop_mcp_bridge.py @@ -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 @@ -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), @@ -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):