[PF-24] Sandbox PATH resolution and Windows EINVAL fix for Claude/Codex - #25
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Purpose
Make both Claude and Codex CLIs run reliably in Cursor agent sandbox (PowerShell on Windows, macOS) by (1) resolving executables from common npm global paths when PATH is restricted, and (2) avoiding EINVAL on Windows by running
.cmdvia PowerShell instead of spawning them directly.Description
Related Notion: Sandbox Path
Summary of changes:
packages/cli-js/src/utils/shell.tsgetNpmGlobalExeCandidates(cmd)andresolveCommandPathWithNpmFallback(cmd)for PATH + npm global fallback (Windows: APPDATA/LOCALAPPDATA npm; Unix: HOME-based paths).packages/cli-js/src/providers/claude.tsresolveClaudeExe()now uses the shared fallback. completeOneTurn and runClaudeStreaming on Windows use a temp file + PowerShell script (Get-Content ... | & 'exe') so.cmdis never spawned directly (avoids EINVAL / CVE-2024-27980).packages/cli-js/src/providers/codex.tsresolveCodexExe(). checkCodex / listModelsCodex use fallback. runCodexExec and runCodexExecStreaming resolve exe first; on Windows the script uses& 'escapedExe' exec -, on non-Windowsspawn(exe, ["exec", fullPrompt], ...).packages/cli-py/planforge/utils/shell.pyget_npm_global_exe_candidates(cmd)andresolve_command_path_with_npm_fallback(cmd)(same path logic as cli-js).packages/cli-py/planforge/providers/claude.pyos.name == "nt"), complete_one_turn and _run_claude_streaming use temp file + PowerShell. run_implement delegates to _run_claude_streaming.packages/cli-py/planforge/providers/codex.py_resolve_codex_exe(). Windows script invokes codex by absolute path (& 'escaped_exe' exec -); non-Windows uses[exe, "exec", full_prompt].claude. On Windows, spawningclaude.cmd(orcodex.cmd) directly from Node can yield EINVAL; running them via PowerShell avoids that.powershell -Command "..."with temp-file or pipe, never by direct spawn of the.cmd.How to test
pnpm run buildinpackages/cli-js— should succeed.planforge doctor ai, choose claude. TC1–TC3 should pass withoutspawnSync ... EINVAL.planforge plan "simple goal"andplanforge implement "simple task"with planner=claude and implementer=codex — both should run without ENOENT/EINVAL.packages/cli-py, run the same flows if you use the Python CLI; behavior should match.Review Requirement
'→'') for safety; please confirm there are no edge cases (e.g. paths with').claude.ts/codex.tsandclaude.py/codex.py.Additional Info
.cursor/rules/provider-symmetry.mdc,node-python-symmetry.mdc, andcross-platform.mdc.