Use Pi agent dir helper

Amolith created

Use pi-coding-agent's getAgentDir helper for extension paths instead of
reconstructing PI_CODING_AGENT_DIR and ~/.pi/agent locally. This keeps
personas and handoff aligned with Pi's own agent directory resolution.

Change summary

packages/handoff/src/session-paths.ts |  7 ++-----
packages/personas/src/index.ts        | 17 +++--------------
2 files changed, 5 insertions(+), 19 deletions(-)

Detailed changes

packages/handoff/src/session-paths.ts 🔗

@@ -4,8 +4,8 @@
 // SPDX-License-Identifier: MIT
 
 import * as fs from "node:fs";
-import * as os from "node:os";
 import * as path from "node:path";
+import { getAgentDir } from "@earendil-works/pi-coding-agent";
 
 export function getSessionsRoot(sessionFile: string | undefined): string | undefined {
 	if (!sessionFile) return undefined;
@@ -19,10 +19,7 @@ export function getSessionsRoot(sessionFile: string | undefined): string | undef
 }
 
 export function getFallbackSessionsRoot(): string | undefined {
-	const configuredDir = process.env.PI_CODING_AGENT_DIR;
-	const candidate = configuredDir
-		? path.resolve(configuredDir, "sessions")
-		: path.resolve(os.homedir(), ".pi", "agent", "sessions");
+	const candidate = path.resolve(getAgentDir(), "sessions");
 	return fs.existsSync(candidate) ? candidate : undefined;
 }
 

packages/personas/src/index.ts 🔗

@@ -7,7 +7,7 @@
  *
  * Switch between agent personas stored as markdown files.
  *
- * Personas live in $PI_CODING_AGENT_DIR/personas/ as .md files.
+ * Personas live in the Pi agent directory's personas/ subdirectory as .md files.
  * The active persona is appended to the system prompt in a <persona>
  * section, independent of SYSTEM.md and AGENTS.md.
  *
@@ -16,26 +16,15 @@
  *   /persona none|unset|clear — Remove active persona
  *
  * The active persona persists across sessions in a plain text file
- * at $PI_CODING_AGENT_DIR/persona.
+ * at persona in the Pi agent directory.
  */
 
 import * as fs from "node:fs";
 import * as path from "node:path";
-import * as os from "node:os";
-import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
+import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
 
 const CLEAR_KEYWORDS = ["none", "unset", "clear"];
 
-function getAgentDir(): string {
-	const envDir = process.env.PI_CODING_AGENT_DIR;
-	if (envDir) {
-		if (envDir === "~") return os.homedir();
-		if (envDir.startsWith("~/")) return path.join(os.homedir(), envDir.slice(2));
-		return envDir;
-	}
-	return path.join(os.homedir(), ".pi", "agent");
-}
-
 function getPersonasDir(): string {
 	return path.join(getAgentDir(), "personas");
 }