Skip to content

Commit febe56f

Browse files
fix(cli): scope doctor session/db discovery to HOME/XDG overrides
Pi recent-session discovery and the OpenCode db probe resolved through bare homedir(), which ignores a runtime HOME override. A doctor run in a sandboxed environment (like the doctor tests) escaped to the real ~/.pi/agent/sessions and surfaced the machine's historian debug dumps, adding a nondeterministic WARN to otherwise-isolated runs. Co-authored-by: Alfonso [Magic Context] <288211368+alfonso-magic-context@users.noreply.github.com>
1 parent 89757c4 commit febe56f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/cli/src/lib/diagnostics-opencode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ function collectHistorianDumps(
438438
* historian dumps fall back to the legacy tmp-dir listing on the empty path.
439439
*/
440440
async function collectRecentSessions(): Promise<RecentSessionSummary[]> {
441-
const opencodeDbPath = join(homedir(), ".local", "share", "opencode", "opencode.db");
441+
// env-first: honor XDG/HOME overrides (and sandboxed doctor test runs)
442+
// instead of Bun's homedir(), which ignores a runtime HOME override.
443+
const dataHome = process.env.XDG_DATA_HOME || join(process.env.HOME || homedir(), ".local", "share");
444+
const opencodeDbPath = join(dataHome, "opencode", "opencode.db");
442445
if (!existsSync(opencodeDbPath)) return [];
443446

444447
if (typeof (globalThis as { Bun?: unknown }).Bun === "undefined") {

packages/cli/src/lib/diagnostics-pi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ function reverseSlugToDirectory(slug: string): string | null {
284284
* doesn't exist (Pi not installed or never used).
285285
*/
286286
function collectPiRecentSessions(): PiRecentSessionSummary[] {
287-
const sessionsRoot = join(homedir(), ".pi", "agent", "sessions");
287+
// env-first like the rest of this file: Bun's homedir() does not follow a
288+
// runtime HOME override, which would let sandboxed doctor runs escape to
289+
// the real ~/.pi/agent/sessions.
290+
const sessionsRoot = join(process.env.HOME || homedir(), ".pi", "agent", "sessions");
288291
if (!existsSync(sessionsRoot)) return [];
289292
try {
290293
const slugs = readdirSync(sessionsRoot, { withFileTypes: true })

0 commit comments

Comments
 (0)