Strip PHPStan agent-detector env vars when spawning PHPStan#149
Closed
SanderRonde wants to merge 2 commits intomasterfrom
Closed
Strip PHPStan agent-detector env vars when spawning PHPStan#149SanderRonde wants to merge 2 commits intomasterfrom
SanderRonde wants to merge 2 commits intomasterfrom
Conversation
PHPStan's AgentDetector reads editor/agent environment variables (e.g. CURSOR_TRACE_ID, CURSOR_AGENT), which can break analysis when the extension runs inside Cursor. Clear the same vars PHPStan checks for all PHPStan child processes, including the Windows exec code path that previously inherited the full environment without overrides. Also apply stripping to the version probe spawn for consistency. Co-authored-by: Sander Ronde <awsdfgvhbjn@gmail.com>
- Format phpstanSpawnEnv and import order in getVersion - Narrow workspace root path before getBinComand (no-unsafe-argument) Co-authored-by: Sander Ronde <awsdfgvhbjn@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the suggestion from issue #148 (comment): when the extension spawns PHPStan, environment variables used by PHPStan’s
AgentDetectorare cleared so analysis is not affected when the editor (e.g. Cursor) setsCURSOR_TRACE_ID,CURSOR_AGENT, etc.Changes
shared/phpstanSpawnEnv.tswith the same variable list as PHPStan’s detector (AI_AGENT,CURSOR_TRACE_ID,CURSOR_AGENT,GEMINI_CLI,CODEX_SANDBOX,AUGMENT_AGENT,OPENCODE_CLIENT,OPENCODE,CLAUDECODE,CLAUDE_CODE,REPL_ID) and a helper to remove them from an env object.Process.spawnWithRobustTimeoutnow buildsspawnEnvfromprocess.envmerged with calleroptions.env, strips those keys, and passesenvto both the Windowsexecpath (which previously omittedenv) and thespawnpath.getVersionuses the same stripping for itsspawncall.Fixes the need for users to manually unset these variables in wrapper scripts when running PHPStan from Cursor-related environments.
Closes #148