The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(lsp): keep vue-language-server out of untrusted workspaces
kshitijk4poor09d14ea13089
diff --git a/agent/lsp/servers.py b/agent/lsp/servers.pyindex df94c4a4c83..50140e36a4a 100644--- a/agent/lsp/servers.py+++ b/agent/lsp/servers.py@@ -269,7 +269,7 @@ def _spawn_vue(root: str, ctx: ServerContext) -> Optional[SpawnSpec]:bin_path = _find_binary(ctx, "vue-language-server", ("vue-language-server",), "@vue/language-server")if bin_path is None:return None- trees = _node_modules_trees(bin_path, root if ctx.trusted else None)+ trees = _node_modules_trees(bin_path, root)if _vue_server_major(trees) >= 3:_warn_once("vue-tunnel", _VUE_TUNNEL_MSG)return None@@ -382,12 +382,12 @@ def hermes_lsp_session_dir() -> str:# The only servers that start in an untrusted workspace (``workspace.is_trusted_workspace``): with the# settings Hermes passes they run nothing the checkout ships. Everything else waits for trust, because# it evaluates project build files on start or on save (cargo check / build.rs / proc-macros, Gradle,-# mix.exs, build.zig, stack/cabal, Lua ``runtime.plugin``, terraform providers, prisma.config.ts, ...),+# mix.exs, build.zig, stack/cabal, Lua ``runtime.plugin``, terraform providers, prisma.config.ts, Vue's+# tsconfig ``vueCompilerOptions.plugins``, which @vue/language-core require()s from the project, ...),# and so do user-declared ``lsp.servers`` entries, whose behaviour Hermes cannot vouch for.UNTRUSTED_SAFE_SERVERS = frozenset({"pyright", # interpreter pinned to the operator's own (_spawn_pyright)"typescript", # tsserver pinned to Hermes's SDK; plugins then resolve beside it (_spawn_typescript)- "vue-language-server", # Hermes's TypeScript SDK only (_spawn_vue)"svelte-language-server", # isTrusted: false — no svelte.config.js, no project svelte/prettier"bash-language-server", # parses scripts; diagnostics from shellcheck on PATH"yaml-language-server", # parses YAML against JSON schemas; no project codediff --git a/tests/agent/lsp/test_workspace_trust.py b/tests/agent/lsp/test_workspace_trust.pyindex 6f9b3717da2..fa6acf21487 100644--- a/tests/agent/lsp/test_workspace_trust.py+++ b/tests/agent/lsp/test_workspace_trust.py@@ -1,7 +1,7 @@"""Nothing a checkout ships runs unless the operator trusts that workspace.A cloned repository can ship its own ``.venv/bin/python`` (pyright executes the configured-interpreter), ``node_modules/typescript`` (typescript-language-server and Vue load it),+interpreter), ``node_modules/typescript`` (typescript-language-server loads it), Vue compiler plugins,``svelte.config.js``, Rust build scripts and Gradle builds (rust-analyzer, jdtls andkotlin-language-server evaluate them), and a ``node_modules/.bin/tsc`` or ``rust-toolchain.toml``the post-write shell linters would pick up. Nothing here executes those files: the tests record@@ -11,11 +11,10 @@ from __future__ import annotationsimport jsonimport os-import shutilfrom types import SimpleNamespacefrom agent.lsp import manager-from agent.lsp.servers import UNTRUSTED_SAFE_SERVERS, ServerContext, find_server_for_file+from agent.lsp.servers import UNTRUSTED_SAFE_SERVERSfrom agent.lsp.workspace import clear_cache, is_inside_workspace_SERVERS = {"pyright": "a.py", "typescript": "a.ts", "vue-language-server": "a.vue",@@ -107,17 +106,14 @@ def test_untrusted_checkout_starts_only_allowlisted_servers_pinned_to_hermes_coduntrusted = {sid: init for (sid, root), init in handed.items() if root == str(clone)}# Deny by default: servers that evaluate build files (cargo, Gradle) never start in the clone.assert set(untrusted) == set(_SERVERS) & UNTRUSTED_SAFE_SERVERS- assert {("rust-analyzer", str(clone)), ("jdtls", str(clone))} <= set(status["untrusted_skipped"])+ assert {("rust-analyzer", str(clone)), ("jdtls", str(clone)), ("vue-language-server", str(clone))} \+ <= set(status["untrusted_skipped"])for sid, init in untrusted.items():leaked = [s for s in _strings(init) if os.path.isabs(s) and is_inside_workspace(s, str(clone))]assert not leaked, (sid, leaked)# Allowlisted servers that would fall back to project code by themselves are told not to.assert os.path.isfile(os.path.join(untrusted["typescript"]["tsserver"]["path"], "tsserver.js"))assert untrusted["svelte-language-server"]["isTrusted"] is False- # With no Hermes-side SDK, Vue is skipped rather than handed the checkout's TypeScript.- shutil.rmtree(os.path.join(os.path.dirname(launcher), "typescript"))- ctx = ServerContext(workspace_root=str(clone), install_strategy="manual", binary_overrides={"vue-language-server": [launcher]})- assert find_server_for_file("a.vue").build_spawn(str(clone), ctx) is None# The launch worktree is trusted: every server starts, pyright gets the project interpreter back.trusted = {sid: init for (sid, root), init in handed.items() if root == str(launch)}diff --git a/website/docs/user-guide/features/lsp.md b/website/docs/user-guide/features/lsp.mdindex f4663ba3ecb..5aa89bbd66f 100644--- a/website/docs/user-guide/features/lsp.md+++ b/website/docs/user-guide/features/lsp.md@@ -89,7 +89,8 @@ servers below start, each with settings that keep it on Hermes-sidetools. Every other server is skipped, including rust-analyzer, gopls,jdtls, kotlin-language-server, elixir-ls, zls, clojure-lsp,haskell-language-server, lua-language-server, terraform-ls, prisma,-astro and any server you declare under `lsp.servers`. The diagnostics+astro, vue-language-server (it loads the `vueCompilerOptions.plugins`+a project's `tsconfig.json` names) and any server you declare under `lsp.servers`. The diagnosticslog records `skipped: untrusted workspace …; add it tolsp.trusted_workspaces`, and `hermes lsp status` marks those servers`[trusted workspaces only]`.@@ -98,7 +99,6 @@ lsp.trusted_workspaces`, and `hermes lsp status` marks those servers|---|---|| pyright | `VIRTUAL_ENV` or the Hermes-managed Python, never the project's `.venv`/`venv` || typescript-language-server | `tsserver.path` pinned to the TypeScript next to the server; skipped if there is none |-| vue-language-server | `tsdk` from Hermes's staging tree only || svelte-language-server | `isTrusted: false` (no `svelte.config.js`, no project `svelte`/`prettier`) || bash-language-server, yaml-language-server, dockerfile-ls, intelephense | unchanged: they only parse files || clangd | unchanged: Hermes never passes `--query-driver`, so no project compiler runs |diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/lsp.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/lsp.mdindex 7cbdc554713..b4fcf044131 100644--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/lsp.md+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/lsp.md@@ -72,7 +72,8 @@ agent 无法扩大信任范围:它在终端里执行 `cd` 不会改变会话使用让它停留在 Hermes 一侧工具上的设置。其他所有服务器都会被跳过,包括rust-analyzer、gopls、jdtls、kotlin-language-server、elixir-ls、zls、clojure-lsp、haskell-language-server、lua-language-server、terraform-ls、-prisma、astro,以及你在 `lsp.servers` 下声明的任何服务器。诊断日志会记录+prisma、astro、vue-language-server(它会加载项目 `tsconfig.json` 中+`vueCompilerOptions.plugins` 指定的插件),以及你在 `lsp.servers` 下声明的任何服务器。诊断日志会记录`skipped: untrusted workspace …; add it to lsp.trusted_workspaces`,`hermes lsp status` 会把这些服务器标记为 `[trusted workspaces only]`。@@ -80,7 +81,6 @@ prisma、astro,以及你在 `lsp.servers` 下声明的任何服务器。诊断|---|---|| pyright | 使用 `VIRTUAL_ENV` 或 Hermes 管理的 Python,绝不使用项目的 `.venv`/`venv` || typescript-language-server | `tsserver.path` 固定为服务器旁边的 TypeScript;若没有则跳过 |-| vue-language-server | `tsdk` 仅取自 Hermes 的暂存目录 || svelte-language-server | `isTrusted: false`(不加载 `svelte.config.js`,不加载项目的 `svelte`/`prettier`) || bash-language-server、yaml-language-server、dockerfile-ls、intelephense | 不变:它们只解析文件 || clangd | 不变:Hermes 从不传入 `--query-driver`,因此不会运行项目的编译器 |