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 22, 22:00 UTC
fix(server): onboarding offers worktrees of a bare repository (#16688)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Chris Allen committed
Oct 20, 2026 at 01:09 UTC
acf5f3bde515f4fd7efadfb82d3546cbb41161e4
4 files changed
+107
-8
apps/server/src/project/AgentSessionScanner.test.ts
+73
-1
@@ -978,9 +978,12 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
978
path.join(repo, ".git", "config"),
979
'[core]\n\tbare = false\n[remote "origin"]\n\turl = git@github.com:pingdotgg/t3code.git\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n',
980
);
981
+ const worktreeGitDir = path.join(repo, ".git", "worktrees", "wt");
982
+ yield* fileSystem.makeDirectory(worktreeGitDir, { recursive: true });
983
+ yield* fileSystem.writeFileString(path.join(worktreeGitDir, "commondir"), "../..\n");
984
yield* fileSystem.writeFileString(
985
path.join(worktree, ".git"),
983
- `gitdir: ${path.join(repo, ".git", "worktrees", "wt")}\n`,
986
+ `gitdir: ${worktreeGitDir}\n`,
987
);
988
yield* fileSystem.makeDirectory(path.join(noRemote, ".git"));
989
yield* fileSystem.writeFileString(path.join(noRemote, ".git", "config"), "[core]\n");
@@ -1022,6 +1025,75 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1025
}),
1026
);
1027
1028
+ it.effect(
1029
+ "offers bare-repository worktrees separately and imports only their own sessions",
1030
+ () =>
1031
+ Effect.gen(function* () {
1032
+ const path = yield* Path.Path;
1033
+ const fileSystem = yield* FileSystem.FileSystem;
1034
+ const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1035
+ yield* TestClock.setTime(nowMs);
1036
+ const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1037
+ const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1038
+ const configBaseDir = yield* makeTempDir("t3code-scanner-base-");
1039
+ const bare = yield* makeTempDir("t3code-workspace-bare-");
1040
+ const bareGitDir = path.join(bare, ".git");
1041
+ yield* fileSystem.makeDirectory(bareGitDir);
1042
+ yield* fileSystem.writeFileString(
1043
+ path.join(bareGitDir, "config"),
1044
+ '[core] bare = "true" ; bare repository\n[remote "origin"]\nurl = git@github.com:pingdotgg/t3code.git\n',
1045
+ );
1046
+ const dev = path.join(bare, "dev");
1047
+ const prod = path.join(bare, "prod");
1048
+ const managed = path.join(configBaseDir, "worktrees", "t3code", "sandbox");
1049
+ for (const [index, cwd] of [bare, dev, prod, managed].entries()) {
1050
+ if (cwd !== bare) {
1051
+ const gitDir = path.join(bareGitDir, "worktrees", path.basename(cwd));
1052
+ yield* fileSystem.makeDirectory(gitDir, { recursive: true });
1053
+ yield* fileSystem.writeFileString(path.join(gitDir, "commondir"), "../..\n");
1054
+ yield* fileSystem.makeDirectory(cwd, { recursive: true });
1055
+ yield* fileSystem.writeFileString(path.join(cwd, ".git"), `gitdir: ${gitDir}\n`);
1056
+ }
1057
+ yield* writeTranscript({
1058
+ filePath: path.join(
1059
+ codexHomePath,
1060
+ "sessions",
1061
+ "2026",
1062
+ "08",
1063
+ "24",
1064
+ `rollout-${index}.jsonl`,
1065
+ ),
1066
+ contents: [
1067
+ encodeTranscriptRecord({
1068
+ type: "session_meta",
1069
+ payload: { id: `session-${index}`, cwd },
1070
+ }),
1071
+ encodeTranscriptRecord({
1072
+ type: "event_msg",
1073
+ payload: { type: "user_message", message: `Work in ${cwd}` },
1074
+ }),
1075
+ ].join("\n"),
1076
+ mtimeMs: nowMs - index * 1_000,
1077
+ });
1078
+ }
1079
+
1080
+ const input = { claudeHomePath, codexHomePath, configBaseDir };
1081
+ const result = yield* runScan(input);
1082
+ const git = { remoteKey: "github.com/pingdotgg/t3code", repository: "pingdotgg/t3code" };
1083
+ expect(
1084
+ result.candidates.map((candidate) => ({ path: candidate.path, git: candidate.git })),
1085
+ ).toEqual([
1086
+ { path: bare, git },
1087
+ { path: dev, git },
1088
+ { path: prod, git },
1089
+ ]);
1090
+ const threads = yield* runRecentThreads({ ...input, workspaceRoot: dev });
1091
+ expect(threads.map((thread) => thread.providerSessionId)).toEqual(["session-1"]);
1092
+ const managedThreads = yield* runRecentThreads({ ...input, workspaceRoot: managed });
1093
+ expect(managedThreads).toEqual([]);
1094
+ }),
1095
+ );
1096
+
1097
it.effect("excludes sandboxes under the configured worktrees dir without .t3 in the path", () =>
1098
Effect.gen(function* () {
1099
const path = yield* Path.Path;
apps/server/src/project/AgentSessionScanner.ts
+12
-6
@@ -26,6 +26,7 @@ import * as Stream from "effect/Stream";
26
27
import {
28
normalizeGitRemoteUrl,
29
+ isBareGitConfig,
30
parseGitHubRepositoryNameWithOwnerFromRemoteUrl,
31
parseOriginUrlFromGitConfig,
32
} from "@t3tools/shared/git";
@@ -687,11 +688,6 @@ export const make = Effect.gen(function* () {
688
return `path:${normalizeProjectPathForComparison(realPath)}`;
689
});
690
690
- /**
691
- * When it points into a `worktrees/` directory the checkout is a linked worktree, which
692
- * onboarding skips because its history belongs to the main checkout. Submodules use the same
693
- * pointer shape but live under `modules/`, and are offered like any other repository.
694
- */
691
const readGitIdentity = Effect.fn("AgentSessionScanner.readGitIdentity")(function* (
692
directory: string,
693
): Effect.fn.Return<
@@ -710,11 +706,21 @@ export const make = Effect.gen(function* () {
706
const target = /^gitdir:\s*(.+)$/m.exec(pointer)?.[1]?.trim();
707
if (target === undefined || target.length === 0) return { _tag: "NotGit" } as const;
708
gitDir = path.resolve(directory, target);
713
- if (/[\\/]worktrees[\\/][^\\/]+[\\/]?$/.test(gitDir)) return { _tag: "Worktree" } as const;
709
+ }
710
+ const linkedWorktree =
711
+ gitStats.value.type !== "Directory" && /[\\/]worktrees[\\/][^\\/]+[\\/]?$/.test(gitDir);
712
+ if (linkedWorktree) {
713
+ const commonDir = yield* fileSystem
714
+ .readFileString(path.join(gitDir, "commondir"))
715
+ .pipe(Effect.orElseSucceed(() => ""));
716
+ if (commonDir.trim().length === 0) return { _tag: "Worktree" } as const;
717
+ gitDir = path.resolve(gitDir, commonDir.trim());
718
}
719
const configText = yield* fileSystem
720
.readFileString(path.join(gitDir, "config"))
721
.pipe(Effect.orElseSucceed(() => ""));
722
+ // Bare repositories have no main checkout, so offer their linked worktrees independently.
723
+ if (linkedWorktree && !isBareGitConfig(configText)) return { _tag: "Worktree" } as const;
724
const originUrl = parseOriginUrlFromGitConfig(configText);
725
return {
726
_tag: "Repository",
docs/user/welcome-wizard.md
+2
-1
@@ -66,7 +66,8 @@ one group. Directories that are not git repositories sit under "Other folders".
66
67
The default selection includes git repositories active within the last 30 days
68
with at least three conversations. Use the checkboxes, or "Select all" and
69
-"Select none", to change the selection. Linked git worktrees, Codex scratch
69
+"Select none", to change the selection. Linked worktrees of bare repositories
70
+can be offered as separate projects. Other linked git worktrees, Codex scratch
71
directories under `Documents/Codex`, and anything under `Downloads` are not
72
offered.
73
packages/shared/src/git.ts
+20
@@ -196,6 +196,26 @@ function parseGitConfigValue(raw: string): string {
196
return out.trim();
197
}
198
199
+export function isBareGitConfig(configText: string): boolean {
200
+ let inCore = false;
201
+ let bare = false;
202
+ for (const rawLine of configText.split(/\r?\n/)) {
203
+ let line = rawLine.trim();
204
+ // Git accepts the first setting on the section header's own line.
205
+ const header = /^\[\s*([^\]]*?)\s*\](.*)$/.exec(line);
206
+ if (header !== null) {
207
+ inCore = header[1]!.toLowerCase() === "core";
208
+ line = header[2]!.trim();
209
+ }
210
+ if (!inCore) continue;
211
+ const match = /^bare\s*(?:=(.*)|[#;].*)?$/i.exec(line);
212
+ if (match === null) continue;
213
+ const value = match[1] === undefined ? "true" : parseGitConfigValue(match[1]).toLowerCase();
214
+ bare = value === "true" || value === "yes" || value === "on" || value === "1";
215
+ }
216
+ return bare;
217
+}
218
+
219
export function parseOriginUrlFromGitConfig(configText: string): string | null {
220
let section: string | null = null;
221
let originUrl: string | null = null;