Expand leading ~ in Codex home paths before exporting CODEX_HOME#2210
Expand leading ~ in Codex home paths before exporting CODEX_HOME#2210juliusmarminge merged 3 commits intopingdotgg:mainfrom
Conversation
Spawned processes don't inherit shell tilde expansion, so a Codex homePath of ~/.codex-work was being passed to the child verbatim as CODEX_HOME=~/.codex-work. The receiver then treats ~ as a relative directory name rather than $HOME, so state ends up in the wrong place (or fails to load existing config). Add an expandHomePath() helper that turns a leading ~ or ~/… into the current user's home directory, and apply it everywhere the Codex homePath setting flows into CODEX_HOME: the text-generation spawn, the discovery probe, the app-server manager spawn and version check, and the Codex provider health check. Leaves other-user (~alice) expansion out — only ~ and ~/… are handled. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The other three expandHomePath helpers in this repo (os-jank.ts, WorkspaceEntries.ts, WorkspacePaths.ts) accept both `~/` and `~\` prefixes. Match that behavior in the new pathExpansion helper so a Windows user who types `~\.codex` into provider settings gets the same expansion as `~/.codex`. Also add a small test file covering the shape of the helper (empty, unchanged, `~`, `~/…`, `~\…`, and `~user` pass-through). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved Straightforward bug fix that expands You can customize Macroscope's approvability policy. Learn more. |
Upstream additions: - fix(web): restore manual sort drag and keep per-group expand state (pingdotgg#2221) - fix: Change right panel sheet to be below title bar / action bar (pingdotgg#2224) - Refactor OpenCode lifecycle and structured output handling (pingdotgg#2218) - effect-codex-app-server (pingdotgg#1942) - Redesign model picker with favorites and search (pingdotgg#2153) - fix(server): prevent probeClaudeCapabilities from wasting API requests (pingdotgg#2192) - fix(server): handle OpenCode text response format in commit message gen (pingdotgg#2202) - Devcontainer / IDE updates (pingdotgg#2208) - Expand leading ~ in Codex home paths before exporting CODEX_HOME (pingdotgg#2210) - fix(release): use v<semver> tag format for nightly releases (pingdotgg#2186) Fork adaptations: - Took upstream's redesigned model picker with favorites and search - Removed deleted codexAppServerManager (replaced by effect-codex-app-server) - Stubbed fetchCodexUsage (manager-based readout no longer available) - Extended PROVIDER_ICON_BY_PROVIDER for all 8 fork providers - Extended modelOptionsByProvider test fixtures for all 8 providers - Inline ClaudeSlashCommand type (not yet re-exported from SDK) - Updated SettingsPanels imports for new picker module structure - Preserved fork's CI customizations (ubuntu-24.04 not Blacksmith)
Summary
Spawned processes don't inherit shell tilde expansion, so a Codex
homePathof~/.codex-workin the server settings was being passed to the child Codex process verbatim asCODEX_HOME=~/.codex-work. The receiver then treats~as a relative directory name rather than$HOME, so state ends up in the wrong place (or fails to load existing config).This PR adds a small
expandHomePath()helper and applies it everywhere the CodexhomePathsetting flows into aCODEX_HOMEenv var passed to a spawned child:CodexAppServerManagerspawn + CLI version checkCodexTextGenerationspawnCodexProvider.runCodexCommandspawn (health check)probeCodexDiscoveryspawnThe helper handles
~alone,~/…, and~\…— matching the behavior of the other threeexpandHomePathimplementations already in the tree (os-jank.ts,WorkspaceEntries.ts,WorkspacePaths.ts). Only~and~//~\are expanded;~user(other-user) is intentionally left alone, same as the existing helpers.Notes for reviewers
CODEX_HOMEenv var that gets propagated to child processes.readCodexConfigModelProviderinCodexProvider.tsalso useshomePathas a direct filesystem path (forconfig.toml) and has the same latent bug, but that's a separate read path — happy to fold that in if you'd prefer a single PR, or leave as a follow-up.expandHomePathhelpers inapps/server/src/. Consolidating them is an easy follow-up, but I kept this PR focused on the user-visible bug. The new helper is a plain function (not Effect-based) because some of the call sites (probeCodexDiscovery, parts ofcodexAppServerManager) are plain async functions.Test plan
vitest run src/pathExpansion.test.ts— new unit tests (empty,~,~/…,~\…,~userpass-through, non-tilde pass-through) all passvitest runfor the touched files (codexAppServerManager.test.ts,CodexTextGeneration.test.ts,pathExpansion.test.ts) — 60 passing, 1 skipped, 0 failingtsc --noEmitcleanhomePath: ~/.codex-worknow land in the correct home directory instead of a literal~folderNote
Low Risk
Low risk: a small, well-tested path normalization helper applied only to
CODEX_HOMEenv propagation for spawned Codex CLI/app-server processes.Overview
Fixes Codex
homePathvalues like~/.codex-workbeing passed literally to child Codex processes by expanding a leading~before exportingCODEX_HOME.Adds a new
expandHomePath()utility (with unit tests) and applies it across all Codex process spawn points, including app-server startup, CLI version checks, provider health checks, discovery probing, and Git text generation.Reviewed by Cursor Bugbot for commit 3463ac5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Expand leading
~inCODEX_HOMEpaths before passing to Codex CLI subprocessesAdds a new
expandHomePathutility inpathExpansion.tsthat resolves a leading~,~/, or~\to the current user's home directory viaos.homedir(). Applies this expansion toCODEX_HOMEin all locations where Codex CLI subprocesses are spawned: the app-server session, version check, text generation, provider command execution, and discovery probing.Macroscope summarized 3463ac5.