The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(server): Pi usage and session import read the instance's home (#34726)
Julius Marminge committed
Nov 11, 2026 at 20:06 UTC
2ab87e16ade5bf6452f55046b76c453ad8c31469
4 files changed
+49
-7
apps/server/src/project/AgentSessionScanner.test.ts
+19
@@ -660,6 +660,8 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
660
const codexWorkspace = yield* makeTempDir("t3code-workspace-codex-");
661
const piWorkspace = yield* makeTempDir("t3code-workspace-pi-");
662
const piFlatWorkspace = yield* makeTempDir("t3code-workspace-pi-flat-");
663
+ const piInstanceHome = yield* makeTempDir("t3code-pi-instance-home-");
664
+ const piHomeWorkspace = yield* makeTempDir("t3code-workspace-pi-home-");
665
666
// Pi nests sessions per cwd by default and keeps a custom session directory flat.
667
for (const [filePath, cwd, mtime] of [
@@ -673,6 +675,11 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
675
piFlatWorkspace,
676
"2026-01-04T00:00:00.000Z",
677
],
678
+ [
679
+ path.join(piInstanceHome, "custom-pi", "sessions", "--slug--", "2026-01-05_pi.jsonl"),
680
+ piHomeWorkspace,
681
+ "2026-01-05T00:00:00.000Z",
682
+ ],
683
] as const) {
684
yield* writeTranscript({
685
filePath,
@@ -731,10 +738,22 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
738
],
739
config: {},
740
},
741
+ [ProviderInstanceId.make("pi-home")]: {
742
+ driver: ProviderDriverKind.make("pi"),
743
+ enabled: true,
744
+ environment: [
745
+ { name: "HOME", value: piInstanceHome, sensitive: false },
746
+ { name: "USERPROFILE", value: piInstanceHome, sensitive: false },
747
+ { name: "PI_CODING_AGENT_DIR", value: "~/custom-pi", sensitive: false },
748
+ { name: "PI_CODING_AGENT_SESSION_DIR", value: "", sensitive: false },
749
+ ],
750
+ config: {},
751
+ },
752
},
753
});
754
755
expect(result.candidates.map((candidate) => [candidate.path, candidate.sources])).toEqual([
756
+ [piHomeWorkspace, ["pi"]],
757
[piFlatWorkspace, ["pi"]],
758
[piWorkspace, ["pi"]],
759
[codexWorkspace, ["codex"]],
apps/server/src/project/AgentSessionScanner.ts
+8
-3
@@ -38,7 +38,7 @@ import * as ProviderSessionRuntime from "../persistence/ProviderSessionRuntime.t
38
import { resolveCodexHomeLayout } from "../provider/Drivers/CodexHomeLayout.ts";
39
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
40
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
41
-import { resolvePiSessionsDir } from "@t3tools/provider-pi/server/usage";
41
+import { piHome, resolvePiSessionsDir } from "@t3tools/provider-pi/server/usage";
42
import * as ServerSettings from "../serverSettings.ts";
43
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
44
import {
@@ -824,7 +824,8 @@ export const make = Effect.gen(function* () {
824
const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
825
const baseDir = path.resolve(serverConfig.baseDir);
826
const worktreesDir = path.resolve(serverConfig.worktreesDir);
827
- const isWindows = (yield* HostProcess.Platform) === "win32";
827
+ const platform = yield* HostProcess.Platform;
828
+ const isWindows = platform === "win32";
829
const foldWorktreeCase = isWindows;
830
const hostEnvironment = yield* HostProcess.Environment;
831
const homeDir = yield* HostProcess.HomeDirectory;
@@ -1591,7 +1592,11 @@ export const make = Effect.gen(function* () {
1592
instance.environment,
1593
hostEnvironment,
1594
).pipe(Effect.provideService(HostProcess.HomeDirectory, homeDir));
1594
- homePath = resolvePiSessionsDir(environment, homeDir, path);
1595
+ homePath = resolvePiSessionsDir(
1596
+ environment,
1597
+ piHome(environment, homeDir, platform),
1598
+ path,
1599
+ );
1600
} else if (source === "claudeAgent") {
1601
const config = decodeClaudeSettings(instance.config ?? {});
1602
if (Option.isNone(config)) continue;
apps/server/src/usage/UsageService.test.ts
+11
-2
@@ -1384,6 +1384,15 @@ describe("UsageService", () => {
1384
"windows-profile",
1385
"win32",
1386
],
1387
+ [undefined, undefined, "pi-home/.pi/agent/sessions", undefined, "pi-home"],
1388
+ ["~/custom-pi", undefined, "pi-agent-home/custom-pi/sessions", undefined, "pi-agent-home"],
1389
+ [
1390
+ "~/ignored-pi",
1391
+ "~/custom-sessions",
1392
+ "pi-session-home/custom-sessions",
1393
+ undefined,
1394
+ "pi-session-home",
1395
+ ],
1396
] as const) {
1397
const dir = NodePath.join(home, relativeDir);
1398
yield* Effect.promise(async () => {
@@ -1423,7 +1432,7 @@ describe("UsageService", () => {
1432
prefix: "usage-pi-" + relativeDir.replaceAll("/", "-"),
1433
home,
1434
settings:
1426
- launchArgs === undefined
1435
+ launchArgs === undefined && instanceHome === undefined
1436
? settings
1437
: {
1438
...settings,
@@ -1431,7 +1440,7 @@ describe("UsageService", () => {
1440
...settings.providerInstances,
1441
[ProviderInstanceId.make("pi")]: {
1442
driver: ProviderDriverKind.make("pi"),
1434
- config: { launchArgs },
1443
+ config: launchArgs === undefined ? {} : { launchArgs },
1444
environment:
1445
instanceHome === undefined
1446
? []
packages/provider-pi/src/server/usage.ts
+11
-2
@@ -133,7 +133,7 @@ export const piUsageReader: ProviderUsageReader<PiSettings, Path.Path> = {
133
const path = yield* Path.Path;
134
const home = yield* HostProcess.HomeDirectory;
135
const platform = yield* HostProcess.Platform;
136
- const launchHome = (platform === "win32" ? environment.USERPROFILE : environment.HOME) || home;
136
+ const launchHome = piHome(environment, home, platform);
137
const sessionDirArg = config === undefined ? undefined : piLaunchSessionDir(config.launchArgs);
138
const launchDir =
139
sessionDirArg === undefined ? undefined : expandHomePath(sessionDirArg, launchHome);
@@ -142,7 +142,7 @@ export const piUsageReader: ProviderUsageReader<PiSettings, Path.Path> = {
142
...(launchDir !== undefined && path.isAbsolute(launchDir)
143
? [{ dir: path.resolve(launchDir) }]
144
: []),
145
- { dir: resolvePiSessionsDir(environment, home, path) },
145
+ { dir: resolvePiSessionsDir(environment, launchHome, path) },
146
];
147
}),
148
};
@@ -160,6 +160,15 @@ function piLaunchSessionDir(launchArgs: string): string | undefined {
160
return sessionDir;
161
}
162
163
+/** The home Pi resolves `~` against: the instance's HOME (USERPROFILE on Windows), else the host's. */
164
+export function piHome(
165
+ environment: NodeJS.ProcessEnv,
166
+ hostHome: string,
167
+ platform: NodeJS.Platform,
168
+): string {
169
+ return (platform === "win32" ? environment.USERPROFILE : environment.HOME) || hostHome;
170
+}
171
+
172
/** Where Pi stores session JSONL files for a provider environment, matching Pi's own lookup. */
173
export function resolvePiSessionsDir(
174
environment: NodeJS.ProcessEnv,