Skip to content

fix: honor PI_CODING_AGENT_DIR instead of hardcoding ~/.pi/agent - #41

Open
Susensio wants to merge 2 commits into
czottmann:mainfrom
Susensio:fix/respect-PI_CODING_AGENT_DIR
Open

Susensio wants to merge 2 commits into
czottmann:mainfrom
Susensio:fix/respect-PI_CODING_AGENT_DIR

Conversation

@Susensio

Copy link
Copy Markdown

Summary

  • resolve pi-automode global config and legacy migration paths from PI_CODING_AGENT_DIR
  • use the effective agent directory for in-memory logs and safety-control path checks
  • document the override and add coverage for custom agent directories

Validation

  • npm run check
  • npm pack --dry-run
  • npm test (299 passed, 1 environment-sensitive timeout in the existing adversarial wildcard child-process test; 3 skipped)

Read, write, migrate, and protect Auto Mode's global config and logs under
Pi's effective agent directory. The extension previously hardcoded
`~/.pi/agent`, which broke setups where `PI_CODING_AGENT_DIR` relocates Pi's
config (e.g. `~/.config/pi/agent`).

A single resolvePiAgentDir() helper resolves the effective directory,
expanding a leading `~` the same way Pi does. Global settings, the legacy
config migration path, the in-memory observability log root, and the
deterministic safety-control protections all follow it. Resolves config paths
at call time so tests can exercise the override directly.
Drop the custom resolvePiAgentDir() wrapper (honoring PI_CODING_AGENT_DIR
was already handled upstream) and hardcoded '/.pi/' segments in favor of
the canonical @earendil-works/pi-coding-agent exports. Adjust the bounded
wildcard child-process timeout for cold-start import cost.
@Susensio

Copy link
Copy Markdown
Author

Removed the duplicated PI_CODING_AGENT_DIR resolution. The extension now uses Pi's canonical getAgentDir() and CONFIG_DIR_NAME directly from @earendil-works/pi-coding-agent, which already handles the env var, tilde expansion, and the ~/.pi/agent default. Source diff is net -38 lines, npm run check and npm test pass.

@czottmann czottmann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this addition, @Susensio! The direction is good. Pi’s getAgentDir() and CONFIG_DIR_NAME avoid duplicated path-resolution logic.

I found one merge blocker, tho.

P1: Canonicalize the effective agent directory before safety-path comparisons

extensions/auto-mode/paths.ts:240 compares a canonicalized target path with the raw value from getAgentDir().

Different path spellings for the same directory make this comparison fail. Examples include:

  • macOS /var and /private/var paths
  • a symlinked agent directory
  • a relative PI_CODING_AGENT_DIR value
  • an agent directory with a trailing separator

The PR’s new test exposes this defect on macOS. tests/agent-dir.test.ts:58 fails because os.tmpdir() uses /var/folders. The target resolves through /private/var/folders (it's a FS link, basically).

This defect removes the deterministic hard-deny for the effective settings.json and extensions/ paths. I reproduced a write(*) allow rule that permitted the settings write with zero classifier calls.

Please canonicalize the agent root with the same policy that resolves the target. One option is resolvePathForPolicy(resolve(getAgentDir())), with the resolved absolute path as the fallback. Please also add regression tests for symlinks, relative paths, and trailing separators.

P2: Update the remaining path documentation

These documents give ~/.pi/agent as the unconditional location:

  • docs/observability-logging.md:47
  • docs/diagnostics.md:68
  • docs/automode-classifier-flow.md:92

Please identify these paths as defaults. State that PI_CODING_AGENT_DIR changes them.

Validation

I tested the PR in an isolated checkout that also contained the newest main branch:

  • npm run check passed.
  • npm pack --dry-run passed.
  • npm test reported 316 passed, 1 failed, and 1 skipped.
  • The test that did not pass is the new agent-directory hard-deny test described above.

Thanks!

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.

2 participants