Skip to content

Commit 844485c

Browse files
dominikzabcikclaude
andcommitted
fix(server): the Welcome page offers repositories you only worked on in worktrees
The project scan dropped sessions whose cwd was a linked git worktree of a normal checkout. A repository where every recent session ran in a worktree (one worktree per task) was never offered, so its root had to be added by hand before any of that history could be imported. The scan now counts a linked worktree's sessions toward its main checkout's project, with the checkout's remote. Only a common dir named `.git` sits inside a checkout, so worktrees of bare repositories keep being offered on their own, and a worktree whose repository config can't be read is still left out, because it could be bare. A main checkout reached through a symlink into an excluded folder is left out too. Importing those sessions into the offered project is #18198. Claude Opus 5.5 and Claude Fable 5.2 in Claude Code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 80e6261 commit 844485c

3 files changed

Lines changed: 139 additions & 36 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
822822
}),
823823
);
824824

825-
it.effect("skips linked git worktrees and reports the origin of real checkouts", () =>
825+
it.effect("folds linked git worktrees into their checkout and reports real origins", () =>
826826
Effect.gen(function* () {
827827
const path = yield* Path.Path;
828828
const fileSystem = yield* FileSystem.FileSystem;
@@ -858,32 +858,91 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
858858
path.join(submodule, ".git"),
859859
`gitdir: ${submoduleGitDir}\n`,
860860
);
861+
// A repository whose sessions all ran in a linked worktree is still offered.
862+
const worktreeOnly = yield* makeTempDir("t3code-workspace-worktree-only-");
863+
const worktreeOnlyCheckout = yield* makeTempDir("t3code-workspace-worktree-only-wt-");
864+
const worktreeOnlyGitDir = path.join(worktreeOnly, ".git", "worktrees", "wt");
865+
yield* fileSystem.makeDirectory(worktreeOnlyGitDir, { recursive: true });
866+
yield* fileSystem.writeFileString(
867+
path.join(worktreeOnly, ".git", "config"),
868+
'[remote "origin"]\n\turl = [email protected]:pingdotgg/other.git\n',
869+
);
870+
yield* fileSystem.writeFileString(path.join(worktreeOnlyGitDir, "commondir"), "../..\n");
871+
yield* fileSystem.writeFileString(
872+
path.join(worktreeOnlyCheckout, ".git"),
873+
`gitdir: ${worktreeOnlyGitDir}\n`,
874+
);
875+
876+
// Not offered: the config is unreadable, so the repository could be bare; and
877+
// the main checkout is reached through a symlink into T3's own state.
878+
const configBaseDir = yield* fileSystem.realPath(
879+
yield* makeTempDir("t3code-scanner-base-"),
880+
);
881+
const links = yield* makeTempDir("t3code-workspace-links-");
882+
const unknown = yield* makeTempDir("t3code-workspace-unknown-");
883+
yield* fileSystem.makeDirectory(path.join(configBaseDir, "state-repo"));
884+
yield* fileSystem.symlink(path.join(configBaseDir, "state-repo"), path.join(links, "repo"));
885+
const hiddenCheckouts: Array<string> = [];
886+
for (const [main, config] of [
887+
[unknown, null],
888+
[path.join(links, "repo"), "[core]\n"],
889+
] as const) {
890+
const gitDir = path.join(main, ".git", "worktrees", "wt");
891+
yield* fileSystem.makeDirectory(gitDir, { recursive: true });
892+
if (config !== null) {
893+
yield* fileSystem.writeFileString(path.join(main, ".git", "config"), config);
894+
}
895+
yield* fileSystem.writeFileString(path.join(gitDir, "commondir"), "../..\n");
896+
const checkout = yield* makeTempDir("t3code-workspace-hidden-wt-");
897+
yield* fileSystem.writeFileString(path.join(checkout, ".git"), `gitdir: ${gitDir}\n`);
898+
hiddenCheckouts.push(checkout);
899+
}
861900

862-
for (const [index, cwd] of [repo, worktree, plain, noRemote, submodule].entries()) {
901+
const sessionDirectories = [
902+
repo,
903+
worktree,
904+
plain,
905+
noRemote,
906+
submodule,
907+
worktreeOnlyCheckout,
908+
...hiddenCheckouts,
909+
];
910+
for (const [index, cwd] of sessionDirectories.entries()) {
863911
yield* writeTranscript({
864912
filePath: path.join(claudeHomePath, "projects", `-slug-${index}`, "a.jsonl"),
865913
contents: claudeSessionLine(cwd),
866914
mtimeMs: Date.parse(`2026-01-0${index + 1}T00:00:00.000Z`),
867915
});
868916
}
869917

870-
const result = yield* runScan({ claudeHomePath, codexHomePath });
918+
const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });
871919

872920
expect(
873-
result.candidates.map((candidate) => ({ path: candidate.path, git: candidate.git })),
921+
result.candidates.map((candidate) => ({
922+
path: candidate.path,
923+
git: candidate.git,
924+
threadCount: candidate.threadCount,
925+
})),
874926
).toEqual([
875927
{
928+
path: worktreeOnly,
929+
git: { remoteKey: "github.com/pingdotgg/other", repository: "pingdotgg/other" },
930+
threadCount: 1,
931+
},
932+
{
933+
threadCount: 1,
876934
path: submodule,
877935
git: {
878936
remoteKey: "gitlab.com/pingdotgg/libs/vendor",
879937
repository: "pingdotgg/libs/vendor",
880938
},
881939
},
882-
{ path: noRemote, git: { remoteKey: null, repository: null } },
883-
{ path: plain, git: null },
940+
{ path: noRemote, git: { remoteKey: null, repository: null }, threadCount: 1 },
941+
{ path: plain, git: null, threadCount: 1 },
884942
{
885943
path: repo,
886944
git: { remoteKey: "github.com/pingdotgg/t3code", repository: "pingdotgg/t3code" },
945+
threadCount: 2,
887946
},
888947
]);
889948
}),

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,11 @@ export const make = Effect.gen(function* () {
876876
) {
877877
type GitIdentity =
878878
| { readonly _tag: "Repository"; readonly git: AgentSessionProjectGit | null }
879-
| { readonly _tag: "Worktree" }
879+
| {
880+
readonly _tag: "Worktree";
881+
readonly mainCheckout: string | null;
882+
readonly git: AgentSessionProjectGit | null;
883+
}
880884
| { readonly _tag: "NotGit" };
881885
const identities = new Map<string, GitIdentity>();
882886
const repositories: Array<{ directory: string; gitDir: string; linkedWorktree: boolean }> = [];
@@ -909,8 +913,9 @@ export const make = Effect.gen(function* () {
909913
);
910914
for (const { directory, gitDir } of linkedWorktrees) {
911915
const commonDir = (commonDirTexts.get(path.join(gitDir, "commondir")) ?? "").trim();
912-
if (commonDir.length === 0) identities.set(directory, { _tag: "Worktree" });
913-
else
916+
if (commonDir.length === 0) {
917+
identities.set(directory, { _tag: "Worktree", mainCheckout: null, git: null });
918+
} else
914919
repositories.push({
915920
directory,
916921
gitDir: path.resolve(gitDir, commonDir),
@@ -923,20 +928,25 @@ export const make = Effect.gen(function* () {
923928
);
924929
for (const { directory, gitDir, linkedWorktree } of repositories) {
925930
const configText = configTexts.get(path.join(gitDir, "config")) ?? "";
931+
const originUrl = parseOriginUrlFromGitConfig(configText);
932+
const git: AgentSessionProjectGit = {
933+
remoteKey:
934+
originUrl === null ? null : sourceControlDefinitions.repositoryKeyFromRemote(originUrl),
935+
repository: repositoryPathFromRemoteUrl(originUrl),
936+
};
926937
// Bare repositories have no main checkout, so offer their linked worktrees independently.
927938
if (linkedWorktree && !isBareGitConfig(configText)) {
928-
identities.set(directory, { _tag: "Worktree" });
939+
identities.set(directory, {
940+
_tag: "Worktree",
941+
// Only a common dir named .git sits inside its main checkout, and an
942+
// unreadable config can't rule out a bare repository.
943+
mainCheckout:
944+
configText.length > 0 && path.basename(gitDir) === ".git" ? path.dirname(gitDir) : null,
945+
git,
946+
});
929947
continue;
930948
}
931-
const originUrl = parseOriginUrlFromGitConfig(configText);
932-
identities.set(directory, {
933-
_tag: "Repository",
934-
git: {
935-
remoteKey:
936-
originUrl === null ? null : sourceControlDefinitions.repositoryKeyFromRemote(originUrl),
937-
repository: repositoryPathFromRemoteUrl(originUrl),
938-
},
939-
});
949+
identities.set(directory, { _tag: "Repository", git });
940950
}
941951
return identities;
942952
});
@@ -1563,36 +1573,69 @@ export const make = Effect.gen(function* () {
15631573
),
15641574
);
15651575

1566-
const directoryKeys = new Map<string, string>();
1567-
const gitIdentities = new Map<string, AgentSessionProjectGit | null>();
1576+
const directoryProjects = new Map<
1577+
string,
1578+
{
1579+
readonly key: string;
1580+
readonly path: string;
1581+
readonly git: AgentSessionProjectGit | null;
1582+
} | null
1583+
>();
15681584

15691585
for (const candidate of raw) {
15701586
const expanded = expandHomePath(candidate.cwd.trim(), homeDir);
15711587
if (!path.isAbsolute(expanded)) continue;
15721588
const resolved = path.resolve(expanded);
15731589
const stats = directories.get(resolved);
15741590
if (stats === undefined || Option.isNone(stats)) continue;
1575-
let key = directoryKeys.get(resolved);
1576-
if (key === undefined) {
1591+
let project = directoryProjects.get(resolved);
1592+
if (project === undefined) {
15771593
const gitIdentity = directoryGitIdentities.get(resolved);
1578-
if (gitIdentity === undefined || gitIdentity._tag === "Worktree") {
1579-
key = "";
1594+
if (gitIdentity === undefined) {
1595+
project = null;
1596+
} else if (gitIdentity._tag === "Worktree") {
1597+
// A linked worktree's sessions count toward its main checkout's project.
1598+
const { mainCheckout } = gitIdentity;
1599+
// Symlinks can disguise excluded paths here too; re-check the target.
1600+
const mainStats =
1601+
mainCheckout === null ||
1602+
isExcludedProjectPath(mainCheckout) ||
1603+
isExcludedProjectPath(
1604+
yield* fileSystem
1605+
.realPath(mainCheckout)
1606+
.pipe(Effect.orElseSucceed(() => mainCheckout)),
1607+
)
1608+
? Option.none()
1609+
: yield* statOption(mainCheckout);
1610+
project =
1611+
mainCheckout !== null &&
1612+
Option.isSome(mainStats) &&
1613+
mainStats.value.type === "Directory"
1614+
? {
1615+
key: yield* directoryIdentity(mainCheckout, mainStats.value),
1616+
path: mainCheckout,
1617+
git: gitIdentity.git,
1618+
}
1619+
: null;
15801620
} else {
1581-
key = yield* directoryIdentity(resolved, stats.value);
1582-
gitIdentities.set(key, gitIdentity._tag === "Repository" ? gitIdentity.git : null);
1621+
project = {
1622+
key: yield* directoryIdentity(resolved, stats.value),
1623+
path: resolved,
1624+
git: gitIdentity._tag === "Repository" ? gitIdentity.git : null,
1625+
};
15831626
}
1584-
directoryKeys.set(resolved, key);
1627+
directoryProjects.set(resolved, project);
15851628
}
1586-
if (key === "") continue;
1629+
if (project === null) continue;
15871630

1588-
const existing = merged.get(key);
1631+
const existing = merged.get(project.key);
15891632
if (!existing) {
1590-
merged.set(key, {
1591-
path: resolved,
1633+
merged.set(project.key, {
1634+
path: project.path,
15921635
sources: [candidate.source],
15931636
threadCount: candidate.threadCount,
15941637
lastActiveAtMs: candidate.lastActiveAtMs,
1595-
git: gitIdentities.get(key) ?? null,
1638+
git: project.git,
15961639
});
15971640
continue;
15981641
}

‎docs/user/welcome-page.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ three conversations, already checked. Projects already in T3 Code are not checke
7474
again. Uncheck the box to start without them, or
7575
select **Review all** to pick from everything found, with "Select all" and
7676
"Select none". Linked worktrees of bare repositories
77-
can be offered as separate projects. Other linked git worktrees, Codex scratch
78-
directories under `Documents/Codex`, and anything under `Downloads` are not
79-
offered.
77+
can be offered as separate projects. Conversations in other linked git worktrees
78+
count toward their main checkout, so a repository is offered even if you only
79+
worked in its worktrees. Codex scratch directories under `Documents/Codex`, and
80+
anything under `Downloads` are not offered.
8081

8182
A large or malformed history can reach the scan limit. T3 Code keeps the
8283
projects it found and warns when projects or conversations may be missing.

0 commit comments

Comments
 (0)