Skip to content

Commit 650cbc6

Browse files
committed
fix(pi): point pi at config dir via PI_CODING_AGENT_DIR instead of redirecting HOME
Pi honors the PI_CODING_AGENT_DIR env var to resolve its config directory (~/.pi/agent), so redirecting /Users/david.okeeffe to APP_DIR/pi-home was unnecessary. The HOME redirect broke macOS keychain default resolution under ucode: the Security framework looks for the login keychain under the redirected HOME, finds none, and security default-keychain returns 'A default keychain could not be found'. As a result gh auth, the git credential helper, and any keychain-backed tool failed inside pi. Setting PI_CODING_AGENT_DIR to the existing PI_CONFIG_DIR preserves config isolation (models.json/settings.json/sessions still land under APP_DIR/pi-home/.pi/agent) while leaving /Users/david.okeeffe as the user's real home, so the login keychain stays discoverable. Tests: the two pi e2e sites monkeypatched PI_UCODE_HOME/PI_CONFIG_PATH to redirect pi at a tmp home. They now also patch PI_CONFIG_DIR (read by build_runtime_env) and PI_SETTINGS_PATH/PI_SETTINGS_BACKUP_PATH (previously masked because the HOME redirect made pi read settings from the un-patched real APP_DIR path).
1 parent 0fed5fd commit 650cbc6

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/ucode/agents/pi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _refresh_forever(state: dict, stop_event: threading.Event) -> None:
237237
def build_runtime_env(token: str) -> dict[str, str]:
238238
env = os.environ.copy()
239239
env["OAUTH_TOKEN"] = token
240-
env["HOME"] = str(PI_UCODE_HOME)
240+
env["PI_CODING_AGENT_DIR"] = str(PI_CONFIG_DIR)
241241
return env
242242

243243

tests/test_agent_pi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_sets_oauth_token(self):
242242

243243
def test_sets_ucode_home(self):
244244
env = pi.build_runtime_env("tok")
245-
assert env["HOME"] == str(pi.PI_UCODE_HOME)
245+
assert env["PI_CODING_AGENT_DIR"] == str(pi.PI_CONFIG_DIR)
246246

247247

248248
class TestPiValidateCmd:

tests/test_e2e.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ def test_launch_pi_per_model(self, tmp_path, monkeypatch, e2e_state, e2e_workspa
910910
config_path = pi_dir / "models.json"
911911
backup_path = tmp_path / "pi-models.backup.json"
912912
monkeypatch.setattr(pi, "PI_UCODE_HOME", pi_home)
913+
monkeypatch.setattr(pi, "PI_CONFIG_DIR", pi_dir)
913914
monkeypatch.setattr(pi, "PI_CONFIG_PATH", config_path)
915+
monkeypatch.setattr(pi, "PI_SETTINGS_PATH", pi_dir / "settings.json")
916+
monkeypatch.setattr(pi, "PI_SETTINGS_BACKUP_PATH", tmp_path / "pi-settings.backup.json")
914917
monkeypatch.setattr(pi, "PI_BACKUP_PATH", backup_path)
915918

916919
failures = []

tests/test_e2e_user_agent.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ def test_user_agent_arrives_at_gateway(self, tmp_path, monkeypatch, capture_serv
325325

326326
monkeypatch.setattr(config_io_mod, "APP_DIR", tmp_path)
327327
monkeypatch.setattr(pi, "PI_UCODE_HOME", pi_home)
328+
monkeypatch.setattr(pi, "PI_CONFIG_DIR", pi_dir)
328329
monkeypatch.setattr(pi, "PI_CONFIG_PATH", config_path)
330+
monkeypatch.setattr(pi, "PI_SETTINGS_PATH", pi_dir / "settings.json")
331+
monkeypatch.setattr(pi, "PI_SETTINGS_BACKUP_PATH", tmp_path / "pi-settings.backup.json")
329332
monkeypatch.setattr(pi, "PI_BACKUP_PATH", tmp_path / "pi.backup.json")
330333

331334
state = {

0 commit comments

Comments
 (0)