From ee7fbbdf8a269f264b8018ed0c2ea4baf2d8f526 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 2 Dec 2026 13:31:13 +0100 Subject: [PATCH 1/3] Prepare the plugin for Claude's directory, and add the Cursor manifest The directory only accepts ${CLAUDE_PLUGIN_ROOT} in server commands: the launcher reads CLAUDE_PROJECT_DIR from the environment, which Claude Code sets for MCP and LSP servers. Declare psalm.dev, and say in the README what the plugin runs and sends. --- .claude-plugin/plugin.json | 11 +++++++---- .cursor-plugin/plugin.json | 28 ++++++++++++++++++++++++++++ README.md | 22 +++++++++++++++++----- tests/LauncherTest.php | 18 ++++++++++++++++-- tests/ManifestTest.php | 10 ++++++++-- 5 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 .cursor-plugin/plugin.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 780b7da..5a99c52 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -10,6 +10,11 @@ "homepage": "https://psalm.dev/docs/running_psalm/ai_agents/", "repository": "https://github.com/psalm/agent-plugins", "license": "MIT", + "network": { + "hosts": [ + "psalm.dev" + ] + }, "keywords": [ "php", "psalm", @@ -22,8 +27,7 @@ "command": "php", "args": [ "${CLAUDE_PLUGIN_ROOT}/scripts/server.php", - "mcp", - "${CLAUDE_PROJECT_DIR}" + "mcp" ] } }, @@ -32,8 +36,7 @@ "command": "php", "args": [ "${CLAUDE_PLUGIN_ROOT}/scripts/server.php", - "lsp", - "${CLAUDE_PROJECT_DIR}" + "lsp" ], "extensionToLanguage": { ".php": "php" diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json new file mode 100644 index 0000000..989a027 --- /dev/null +++ b/.cursor-plugin/plugin.json @@ -0,0 +1,28 @@ +{ + "name": "psalm", + "version": "1.0.0", + "description": "Psalm static analysis for PHP: MCP tools to check code, inspect inferred types, find references and explain issues, and the Psalm skill.", + "author": { + "name": "Psalm" + }, + "homepage": "https://psalm.dev/docs/running_psalm/ai_agents/", + "repository": "https://github.com/psalm/agent-plugins", + "license": "MIT", + "keywords": [ + "php", + "psalm", + "static-analysis", + "mcp" + ], + "logo": ".claude-plugin/icon.png", + "mcpServers": { + "psalm": { + "command": "php", + "args": [ + "${CURSOR_PLUGIN_ROOT}/scripts/server.php", + "mcp", + "${workspaceFolder}" + ] + } + } +} diff --git a/README.md b/README.md index f6eebf0..aa68da2 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,6 @@ gives an agent: - a skill to run Psalm, fix its issues and annotate code, which is the one the Psalm of your project ships; - in Claude Code, the language server, which shows Psalm's errors after each edit. -The plugin runs the Psalm of your project on your machine, with `php`. Psalm loads the project's autoloader and Psalm -plugins, so use it in projects you trust. Code leaves your machine only if you agree to upload a snippet to psalm.dev -for a bug report. - ## Setup Install Psalm in the project with `composer require --dev vimeo/psalm`, and create its config with @@ -26,6 +22,8 @@ Gemini CLI: `gemini extensions install https://github.com/psalm/agent-plugins` OpenCode: `opencode plugin add github:psalm/agent-plugins` +Cursor: `agent plugin install https://github.com/psalm/agent-plugins` + Two environment variables change what the plugin runs: - `PSALM_PHP`: the PHP binary that runs Psalm; @@ -33,6 +31,20 @@ Two environment variables change what the plugin runs: Other agents: [Using Psalm with AI agents](https://psalm.dev/docs/running_psalm/ai_agents/). +## What the plugin runs and sends + +- `php scripts/server.php` starts when the agent does. It looks for the Psalm of the project (in `vendor/`, + `vendor-bin/*/vendor/`, `tools/`, the global Composer packages, then the `PATH`) and runs its MCP server + (`psalm-mcp`) or, in Claude Code, its language server (`psalm-language-server`), in the project directory. If there + is no Psalm, the MCP server only says how to install it. +- Psalm loads the project's Composer autoloader and the Psalm plugins in its `psalm.xml`, so use the plugin in + projects you trust. `psalm_check` without paths runs the project's `psalm` command. +- The skill runs the scripts of the skill that the project's Psalm ships, in `vendor/vimeo/psalm/skills/psalm`. +- Nothing is sent anywhere by default. The skill can send a self-contained snippet to `https://psalm.dev/check`, to + check a bug report against the latest Psalm, only after you agree, and it reads the documentation on psalm.dev. + The plugin downloads nothing and collects no data. + ## Releasing -Set the same version in `.claude-plugin/plugin.json`, `gemini-extension.json` and `package.json`, and tag it. +Set the same version in `.claude-plugin/plugin.json`, `.cursor-plugin/plugin.json`, `gemini-extension.json` and +`package.json`, and tag it. diff --git a/tests/LauncherTest.php b/tests/LauncherTest.php index 5923d0c..8eb28e0 100644 --- a/tests/LauncherTest.php +++ b/tests/LauncherTest.php @@ -97,6 +97,20 @@ public function testIgnoresAPlaceholderTheAgentDoesNotKnow(): void self::assertSame("project\n", $this->launch('${CLAUDE_PROJECT_DIR}')); } + public function testRunsTheProjectOfTheAgent(): void + { + $this->writeProject('project', 'project'); + + self::assertSame("project\n", $this->launch(null, ['CLAUDE_PROJECT_DIR' => $this->dir . '/project'])); + } + + public function testRunsTheProjectOfTheWorkingDirectory(): void + { + $this->writeProject('', 'project'); + + self::assertSame("project\n", $this->launch(null)); + } + public function testFindsTheOnlyProjectOfTheRepository(): void { mkdir($this->dir . '/.git'); @@ -220,11 +234,11 @@ private function writeProject(string $path, string $line, string $vendor = 'vend /** * @param array $env */ - private function launch(string $project, array $env = [], string $mode = 'mcp'): string + private function launch(?string $project, array $env = [], string $mode = 'mcp'): string { $nowhere = $this->dir . '/nowhere'; $process = proc_open( - [PHP_BINARY, __DIR__ . '/../scripts/server.php', $mode, $project], + [PHP_BINARY, __DIR__ . '/../scripts/server.php', $mode, ...($project === null ? [] : [$project])], [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes, $this->dir, diff --git a/tests/ManifestTest.php b/tests/ManifestTest.php index bff0104..7a812cb 100644 --- a/tests/ManifestTest.php +++ b/tests/ManifestTest.php @@ -17,6 +17,7 @@ public function testTheManifestsHaveTheSameVersion(): void self::assertIsString($version); self::assertSame($version, self::readJson('gemini-extension.json')['version'] ?? null); self::assertSame($version, self::readJson('package.json')['version'] ?? null); + self::assertSame($version, self::readJson('.cursor-plugin/plugin.json')['version'] ?? null); } public function testThePluginsStartTheLauncher(): void @@ -24,11 +25,11 @@ public function testThePluginsStartTheLauncher(): void $plugin = self::readJson('.claude-plugin/plugin.json'); self::assertSame(['psalm' => [ 'command' => 'php', - 'args' => ['${CLAUDE_PLUGIN_ROOT}/scripts/server.php', 'mcp', '${CLAUDE_PROJECT_DIR}'], + 'args' => ['${CLAUDE_PLUGIN_ROOT}/scripts/server.php', 'mcp'], ]], $plugin['mcpServers'] ?? null); self::assertSame(['psalm' => [ 'command' => 'php', - 'args' => ['${CLAUDE_PLUGIN_ROOT}/scripts/server.php', 'lsp', '${CLAUDE_PROJECT_DIR}'], + 'args' => ['${CLAUDE_PLUGIN_ROOT}/scripts/server.php', 'lsp'], 'extensionToLanguage' => ['.php' => 'php'], 'startupTimeout' => 300_000, ]], $plugin['lspServers'] ?? null); @@ -38,6 +39,11 @@ public function testThePluginsStartTheLauncher(): void 'args' => ['${extensionPath}/scripts/server.php', 'mcp', '${workspacePath}'], ]], self::readJson('gemini-extension.json')['mcpServers'] ?? null); + self::assertSame(['psalm' => [ + 'command' => 'php', + 'args' => ['${CURSOR_PLUGIN_ROOT}/scripts/server.php', 'mcp', '${workspaceFolder}'], + ]], self::readJson('.cursor-plugin/plugin.json')['mcpServers'] ?? null); + self::assertStringContainsString( 'join(root, "scripts", "server.php")', (string) file_get_contents(self::ROOT . '/opencode/index.js'), From 5038e053b8a58731a2468763b21a2731e9dfbc12 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 2 Dec 2026 13:55:31 +0100 Subject: [PATCH 2/3] Find the project when the agent starts the server in the plugin Copilot CLI starts plugin servers in the plugin's directory, which has a composer.json: the launcher took it for the project. Use the session directory that Copilot sets (COPILOT_SESSION_CWD), then $PWD, and never the plugin's own directory. --- README.md | 2 ++ scripts/server.php | 13 +++++++++++-- tests/LauncherTest.php | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index aa68da2..9dc0e9c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ OpenCode: `opencode plugin add github:psalm/agent-plugins` Cursor: `agent plugin install https://github.com/psalm/agent-plugins` +GitHub Copilot CLI: `copilot plugin marketplace add psalm/agent-plugins`, then `copilot plugin install psalm@psalm` + Two environment variables change what the plugin runs: - `PSALM_PHP`: the PHP binary that runs Psalm; diff --git a/scripts/server.php b/scripts/server.php index 3521dd3..da812a3 100644 --- a/scripts/server.php +++ b/scripts/server.php @@ -7,7 +7,8 @@ Starts the Psalm of a PHP project as an MCP server (mcp) or a language server (lsp), on stdin and stdout. It looks for Psalm in the project (vendor/vimeo/psalm, psalm/phar, vendor-bin/*, tools/*), in the global -Composer packages, then on the PATH. PROJECT_DIR defaults to $CLAUDE_PROJECT_DIR, then to the current directory. +Composer packages, then on the PATH. PROJECT_DIR defaults to $CLAUDE_PROJECT_DIR, $COPILOT_SESSION_CWD, the current +directory, then $PWD, leaving out the directory of the plugin. Arguments after PROJECT_DIR are passed on to the server. Environment: @@ -254,7 +255,15 @@ function serveProblem(string $problem): never // agents that don't know a placeholder of a plugin pass it as it is $start = getenv('PSALM_PROJECT_DIR') ?: $argv[2] ?? ''; if ($start === '' || str_starts_with($start, '${')) { - $start = getenv('CLAUDE_PROJECT_DIR') ?: getcwd(); + // the directory of the agent's session: Copilot CLI starts servers in the directory of the plugin + $start = false; + $plugin = (string) realpath(dirname(__DIR__)); + foreach ([getenv('CLAUDE_PROJECT_DIR'), getenv('COPILOT_SESSION_CWD'), getcwd(), getenv('PWD')] as $dir) { + if (is_string($dir) && $dir !== '' && is_dir($dir) && !isInside($dir, $plugin)) { + $start = $dir; + break; + } + } } $start = is_string($start) ? realpath($start) : false; if ($start === false) { diff --git a/tests/LauncherTest.php b/tests/LauncherTest.php index 8eb28e0..3aa8fc6 100644 --- a/tests/LauncherTest.php +++ b/tests/LauncherTest.php @@ -111,6 +111,27 @@ public function testRunsTheProjectOfTheWorkingDirectory(): void self::assertSame("project\n", $this->launch(null)); } + public function testRunsTheProjectOfTheCopilotSession(): void + { + $this->writeProject('project', 'project'); + + self::assertSame("project\n", $this->launch(null, ['COPILOT_SESSION_CWD' => $this->dir . '/project'])); + } + + public function testDoesNotTakeTheDirectoryOfThePluginForTheProject(): void + { + $plugin = $this->dir . '/plugin'; + mkdir($plugin . '/scripts', 0777, true); + copy(__DIR__ . '/../scripts/server.php', $plugin . '/scripts/server.php'); + file_put_contents($plugin . '/composer.json', '{}'); + $this->writeProject('project', 'project'); + + self::assertSame( + "project\n", + $this->launch(null, ['PWD' => $this->dir . '/project'], launcher: $plugin, cwd: $plugin), + ); + } + public function testFindsTheOnlyProjectOfTheRepository(): void { mkdir($this->dir . '/.git'); @@ -234,14 +255,20 @@ private function writeProject(string $path, string $line, string $vendor = 'vend /** * @param array $env */ - private function launch(?string $project, array $env = [], string $mode = 'mcp'): string + private function launch( + ?string $project, + array $env = [], + string $mode = 'mcp', + string $launcher = __DIR__ . '/..', + ?string $cwd = null, + ): string { $nowhere = $this->dir . '/nowhere'; $process = proc_open( - [PHP_BINARY, __DIR__ . '/../scripts/server.php', $mode, ...($project === null ? [] : [$project])], + [PHP_BINARY, $launcher . '/scripts/server.php', $mode, ...($project === null ? [] : [$project])], [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes, - $this->dir, + $cwd ?? $this->dir, // no global Psalm $env + [ 'PATH' => '', From 89d45f15c55727f8a3053133dab86412d3ab573a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 2 Dec 2026 13:55:59 +0100 Subject: [PATCH 3/3] Declare shepherd.dev, where Psalm sends its results with --shepherd --- .claude-plugin/plugin.json | 3 ++- README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 5a99c52..ee100ee 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -12,7 +12,8 @@ "license": "MIT", "network": { "hosts": [ - "psalm.dev" + "psalm.dev", + "shepherd.dev" ] }, "keywords": [ diff --git a/README.md b/README.md index 9dc0e9c..01f500f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,8 @@ Other agents: [Using Psalm with AI agents](https://psalm.dev/docs/running_psalm/ - The skill runs the scripts of the skill that the project's Psalm ships, in `vendor/vimeo/psalm/skills/psalm`. - Nothing is sent anywhere by default. The skill can send a self-contained snippet to `https://psalm.dev/check`, to check a bug report against the latest Psalm, only after you agree, and it reads the documentation on psalm.dev. - The plugin downloads nothing and collects no data. + Psalm sends its results to `https://shepherd.dev` only when it runs with `--shepherd`. The plugin downloads nothing + and collects no data. ## Releasing