Skip to content

fix: honor PI_CODING_AGENT_DIR env override for Pi paths#74

Merged
marcusolsson merged 1 commit into
mainfrom
fix/pi-agent-dir-override
Jun 3, 2026
Merged

fix: honor PI_CODING_AGENT_DIR env override for Pi paths#74
marcusolsson merged 1 commit into
mainfrom
fix/pi-agent-dir-override

Conversation

@marcusolsson

Copy link
Copy Markdown
Contributor

Problem

The CLI hardcoded Pi's agent directory as ~/.pi/agent, ignoring the PI_CODING_AGENT_DIR env override that Pi supports. It also used string concatenation with forward slashes for the Pi auth path, which produces mixed path separators on Windows.

Pi resolves its agent dir via getAgentDir() in src/config.ts:

  • Honors PI_CODING_AGENT_DIR (tilde-expanded, including ~\ on Windows)
  • Falls back to homedir() + /.pi/agent
  • No XDG, no platform-specific branches

Changes

  • Updated: src/commands/code/xdg-paths.ts

    • Added getPiAgentDir(homeDir) — honors PI_CODING_AGENT_DIR with tilde expansion
    • Added getPiAuthPath(homeDir)agentDir/auth.json
    • Added getPiSettingsPath(homeDir)agentDir/settings.json
    • Added expandTilde() helper handling ~/, ~\, and bare ~
  • Updated: src/commands/code/pi.ts — uses new resolvers for settings.json and SYSTEM.md

  • Updated: src/commands/code/auth-sync.ts — uses getPiAuthPath() instead of string concat

  • New: src/commands/code/__tests__/xdg-paths.test.ts — 21 tests covering all Pi and OpenCode path resolution paths

Verification

All 244 tests pass.

Checklist

  • Resolve agent dir as: PI_CODING_AGENT_DIR if set (tilde-expanded), else homedir + /.pi/agent
  • Use path-join instead of string concatenation
  • Write global config to <agentDir>/settings.json
  • Honor PI_CODING_AGENT_DIR
  • Do NOT reuse OpenCode's XDG logic for Pi
  • Do NOT use %APPDATA% or %LOCALAPPDATA% on Windows

Pi uses a single agent directory (`~/.pi/agent`) and does not use XDG.
The base dir can be overridden with the PI_CODING_AGENT_DIR env var
(tilde-expanded, including ~\ on Windows).

Previous code hardcoded ~/.pi/agent for Pi auth, settings, and SYSTEM.md,
ignoring the env override. It also used string concatenation for the Pi auth
path, producing mixed separators on Windows.

Changes:
- Add Pi path resolvers to xdg-paths.ts (getPiAgentDir, getPiAuthPath, getPiSettingsPath)
- Add expandTilde helper for PI_CODING_AGENT_DIR tilde expansion
- Update pi.ts to use new resolvers for settings.json and SYSTEM.md paths
- Update auth-sync.ts to use getPiAuthPath instead of string concatenation
- Add comprehensive tests for xdg-paths.ts (21 tests)

All 244 tests pass.
@marcusolsson marcusolsson force-pushed the fix/pi-agent-dir-override branch from e4d070c to 0887f56 Compare June 3, 2026 15:19
@marcusolsson marcusolsson merged commit 6d6b82f into main Jun 3, 2026
1 check passed
@marcusolsson marcusolsson deleted the fix/pi-agent-dir-override branch June 3, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant