Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/server/src/project/AgentSessionScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,36 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
}),
);

it.effect.skipIf(!symlinksSupported)(
"excludes T3 Code's own folders when its home is reached through a symlink",
() =>
Effect.gen(function* () {
const path = yield* Path.Path;
const fileSystem = yield* FileSystem.FileSystem;
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
const realBaseDir = yield* fileSystem.realPath(
yield* makeTempDir("t3code-scanner-base-"),
);
const linkParent = yield* makeTempDir("t3code-scanner-links-");
const configBaseDir = path.join(linkParent, "t3-home");
yield* fileSystem.symlink(realBaseDir, configBaseDir);

// Providers record the resolved cwd, so a projectless chat shows up under the real home.
const scratchCwd = path.join(realBaseDir, "scratch", "2026-01-01-quiet-fox");
yield* fileSystem.makeDirectory(scratchCwd, { recursive: true });
yield* writeTranscript({
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
contents: claudeSessionLine(scratchCwd),
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
});

const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });

expect(result.candidates).toEqual([]);
}),
);

it.effect("finds the cwd on a later line when the first records carry none", () =>
Effect.gen(function* () {
const path = yield* Path.Path;
Expand Down
20 changes: 15 additions & 5 deletions apps/server/src/project/AgentSessionScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,14 @@ export const make = Effect.gen(function* () {
const serverConfig = yield* ServerConfig.ServerConfig;
const serverSettings = yield* ServerSettings.ServerSettingsService;
const projectStore = yield* ProjectStore.ProjectStoreV2;
const baseDir = path.resolve(serverConfig.baseDir);
const worktreesDir = path.resolve(serverConfig.worktreesDir);
const withResolvedLinks = (directory: string) =>
fileSystem.realPath(directory).pipe(
Effect.map((realPath) => [directory, realPath]),
Effect.orElseSucceed(() => [directory]),
);
// Candidates are also checked with links resolved, so T3's own folders need both spellings.
const baseDirs = yield* withResolvedLinks(path.resolve(serverConfig.baseDir));
const worktreesDirs = yield* withResolvedLinks(path.resolve(serverConfig.worktreesDir));
const foldWorktreeCase = (yield* HostProcess.Platform) === "win32";
const hostEnvironment = yield* HostProcess.Environment;
const homeDir = yield* HostProcess.HomeDirectory;
Expand All @@ -662,10 +668,14 @@ export const make = Effect.gen(function* () {
normalizeForWorktreeMatch(ancestor, foldWorktreeCase),
),
) ||
normalizeForWorktreeMatch(candidatePath, foldWorktreeCase).startsWith(
normalizeForWorktreeMatch(baseDir, foldWorktreeCase),
baseDirs.some((baseDir) =>
normalizeForWorktreeMatch(candidatePath, foldWorktreeCase).startsWith(
normalizeForWorktreeMatch(baseDir, foldWorktreeCase),
),
) ||
isT3ManagedWorktree(candidatePath, worktreesDir, foldWorktreeCase);
worktreesDirs.some((worktreesDir) =>
isT3ManagedWorktree(candidatePath, worktreesDir, foldWorktreeCase),
);

const listDirectory = (directory: string) =>
fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
Expand Down
Loading