From 5d6a0ea00736c7ba7e8713bbc93788cd803a2f16 Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Wed, 18 Nov 2026 01:22:27 -0300 Subject: [PATCH 1/3] fix(server): the Welcome page lists only projects with conversations inside the import window --- .../src/project/AgentSessionScanner.test.ts | 43 ++++++++++ .../server/src/project/AgentSessionScanner.ts | 11 ++- docs/user/welcome-page.md | 15 ++-- ...lists-projects-inside-import-window.e2e.ts | 84 +++++++++++++++++++ 4 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 9c62ddb1a2b84..b210c0ebce0a9 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -973,6 +973,42 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { }), ); + it.effect("lists only projects with conversations inside the import window", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const nowMs = Date.parse("2026-08-24T12:00:00.000Z"); + yield* TestClock.setTime(nowMs); + const claudeHomePath = yield* makeTempDir("t3code-window-claude-"); + const codexHomePath = yield* makeTempDir("t3code-window-codex-"); + const mixedWorkspace = yield* makeTempDir("t3code-window-mixed-"); + const olderWorkspace = yield* makeTempDir("t3code-window-older-"); + + for (const [workspace, name, ageDays] of [ + [mixedWorkspace, "recent", 1], + [mixedWorkspace, "old", 31], + [olderWorkspace, "older", 45], + [olderWorkspace, "oldest", 60], + ] as const) { + yield* writeTranscript({ + filePath: path.join( + claudeHomePath, + "projects", + `-${path.basename(workspace)}`, + `${name}.jsonl`, + ), + contents: claudeSessionLine(workspace), + mtimeMs: nowMs - ageDays * 24 * 60 * 60 * 1000, + }); + } + + const result = yield* runScan({ claudeHomePath, codexHomePath }); + + expect(result.candidates.map(({ path, threadCount }) => ({ path, threadCount }))).toEqual([ + { path: mixedWorkspace, threadCount: 1 }, + ]); + }), + ); + it.effect("drops candidates whose directory no longer exists", () => Effect.gen(function* () { const path = yield* Path.Path; @@ -994,6 +1030,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("excludes the home directory, temporary root, and T3 data directory", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const configBaseDir = yield* makeTempDir("t3code-scanner-base-"); @@ -1042,6 +1079,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("folds linked git worktrees into their checkout and reports real origins", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-10T00:00:00.000Z")); const fileSystem = yield* FileSystem.FileSystem; const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); @@ -1348,6 +1386,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("finds the cwd on a later line when the first records carry none", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const workspace = yield* makeTempDir("t3code-workspace-"); @@ -1368,6 +1407,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("reads a complete transcript record at the exact chunk boundary", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const workspace = yield* makeTempDir("t3code-workspace-"); @@ -1392,6 +1432,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("skips malformed transcripts without failing the scan", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-05-04T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const workspace = yield* makeTempDir("t3code-workspace-"); @@ -1432,6 +1473,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-05-04T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const workspace = yield* makeTempDir("t3code-workspace-"); @@ -1462,6 +1504,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("discovers projects whose Codex rollouts are zstd-compressed", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-05-04T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const workspace = yield* makeTempDir("t3code-workspace-"); diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 1e300d1fe0410..03f3725468712 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -1881,7 +1881,16 @@ export const make = Effect.gen(function* () { const scan: AgentSessionScanner["Service"]["scan"] = Effect.gen(function* () { cachedCandidates = yield* collectCandidates(); - const { candidates: raw, truncated } = cachedCandidates; + const { candidates: collected, truncated } = cachedCandidates; + // Import skips conversations older than the window, so only those inside it count toward a + // project. Future-dated files still count, so clock skew cannot hide a project. + const cutoffMs = DateTime.toEpochMillis(yield* DateTime.now) - RECENT_THREAD_WINDOW_MS; + const raw = collected.flatMap((candidate) => { + const threadCount = candidate.transcripts.filter( + (transcript) => transcript.mtimeMs !== null && transcript.mtimeMs >= cutoffMs, + ).length; + return threadCount === 0 ? [] : [{ ...candidate, threadCount }]; + }); const merged = new Map< string, diff --git a/docs/user/welcome-page.md b/docs/user/welcome-page.md index a914349694156..4f0f4a1b57d5b 100644 --- a/docs/user/welcome-page.md +++ b/docs/user/welcome-page.md @@ -64,13 +64,14 @@ app with a code from **Settings → Sharing & access**. ## Projects -T3 Code finds directories that Claude Code, Codex or Pi has used. Git repositories -are listed first, newest activity on top. When the remote is on GitHub, the -group shows the repository as `owner/name`. Clones with the same remote share -one group. Directories that are not git repositories sit under "Other folders". - -The page offers git repositories active within the last 30 days with at least -three conversations, already checked. Projects already in T3 Code are not checked +T3 Code finds directories that Claude Code, Codex or Pi has used in the last 30 +days. Git repositories are listed first, newest activity on top. When the remote +is on GitHub, the group shows the repository as `owner/name`. Clones with the +same remote share one group. Directories that are not git repositories sit under +"Other folders". + +The page offers git repositories with at least three conversations in that time, +already checked. Projects already in T3 Code are not checked again. Uncheck the box to start without them, or select **Review all** to pick from everything found, with "Select all" and "Select none". Linked worktrees of bare repositories diff --git a/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts b/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts new file mode 100644 index 0000000000000..8bf149f74be22 --- /dev/null +++ b/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts @@ -0,0 +1,84 @@ +// @effect-diagnostics nodeBuiltinImport:off - the scenario writes a Codex history and its settings. +import * as NodeFSP from "node:fs/promises"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; + +import { expect } from "e2e"; +import * as DateTime from "effect/DateTime"; + +import { T3_HOME } from "../e2e.config.ts"; +import { run } from "./shell.ts"; +import { runPromise, test, WEB } from "./t3.ts"; + +const rollout = (id: string, cwd: string, timestamp: string) => + [ + { timestamp, type: "session_meta", payload: { id, cwd } }, + { + timestamp, + type: "event_msg", + payload: { type: "user_message", message: `Work on ${NodePath.basename(cwd)}` }, + }, + { + timestamp, + type: "response_item", + payload: { + type: "message", + role: "assistant", + content: [{ type: "output_text", text: "Done." }], + }, + }, + ] + .map((record) => JSON.stringify(record)) + .join("\n"); + +test( + "The Welcome page lists only projects with conversations inside the import window", + WEB, + async ({ t3, app, screen }) => { + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-scenario-window-")); + const codexHome = NodePath.join(root, "codex"); + const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json"); + const originalSettings = await NodeFSP.readFile(settingsPath, "utf8"); + try { + const now = await runPromise(DateTime.now); + for (const [project, ages] of [ + ["recent-app", [2, 45]], + ["archived-app", [60, 90]], + ] as const) { + const workspace = NodePath.join(root, project); + await NodeFSP.mkdir(workspace); + await runPromise(run("git", ["init", "--quiet"], { cwd: workspace })); + for (const ageDays of ages) { + const at = DateTime.subtract(now, { days: ageDays }); + const timestamp = DateTime.formatIso(at); + const seconds = DateTime.toEpochMillis(at) / 1000; + const id = `${project}-${ageDays}`; + const day = timestamp.slice(0, 10).split("-"); + const file = NodePath.join(codexHome, "sessions", ...day, `rollout-${id}.jsonl`); + await NodeFSP.mkdir(NodePath.dirname(file), { recursive: true }); + await NodeFSP.writeFile(file, rollout(id, workspace, timestamp)); + await NodeFSP.utimes(file, seconds, seconds); + } + } + const settings = JSON.parse(originalSettings); + settings.providerInstances.codex = { + ...settings.providerInstances.codex, + enabled: true, + config: { ...settings.providerInstances.codex.config, homePath: codexHome }, + }; + await NodeFSP.writeFile(settingsPath, JSON.stringify(settings)); + + await t3.open("/welcome"); + const reviewAll = screen.getByRole("button", /^Review all/); + await expect(reviewAll).toBeVisible({ timeout: 60_000 }); + await reviewAll.tap(); + await expect(screen.getByText("recent-app").first()).toBeVisible({ timeout: 60_000 }); + await app.screenshot("project-list"); + + await expect(screen.getByText("archived-app")).toHaveCount(0); + } finally { + await NodeFSP.writeFile(settingsPath, originalSettings); + await NodeFSP.rm(root, { recursive: true, force: true }); + } + }, +); From ca5f44e30cbc3c21bf23518220a9690f4851c65d Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Wed, 18 Nov 2026 01:49:06 -0300 Subject: [PATCH 2/3] test(server): pin the clock in the scan exclusion tests --- apps/server/src/project/AgentSessionScanner.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index b210c0ebce0a9..aeb01138fb01b 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -1012,6 +1012,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("drops candidates whose directory no longer exists", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); @@ -1058,6 +1059,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("excludes T3-managed worktree sandboxes", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const fileSystem = yield* FileSystem.FileSystem; @@ -1339,6 +1341,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("excludes sandboxes under the configured worktrees dir without .t3 in the path", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const configBaseDir = yield* makeTempDir("t3code-scanner-base-"); @@ -1361,6 +1364,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => { it.effect("excludes sandboxes reached through a symlink into the worktrees dir", () => Effect.gen(function* () { const path = yield* Path.Path; + yield* TestClock.setTime(Date.parse("2026-01-02T00:00:00.000Z")); const claudeHomePath = yield* makeTempDir("t3code-claude-home-"); const codexHomePath = yield* makeTempDir("t3code-codex-home-"); const configBaseDir = yield* makeTempDir("t3code-scanner-base-"); From 3e637e2c098de67054e033ec50f13eed06c9d6f3 Mon Sep 17 00:00:00 2001 From: Matheus Marques Botelho Date: Wed, 18 Nov 2026 08:43:21 -0300 Subject: [PATCH 3/3] test(scripts): drop the scenario that repeats the scanner regression test --- ...lists-projects-inside-import-window.e2e.ts | 84 ------------------- 1 file changed, 84 deletions(-) delete mode 100644 scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts diff --git a/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts b/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts deleted file mode 100644 index 8bf149f74be22..0000000000000 --- a/scripts/scenarios/welcome-lists-projects-inside-import-window.e2e.ts +++ /dev/null @@ -1,84 +0,0 @@ -// @effect-diagnostics nodeBuiltinImport:off - the scenario writes a Codex history and its settings. -import * as NodeFSP from "node:fs/promises"; -import * as NodeOS from "node:os"; -import * as NodePath from "node:path"; - -import { expect } from "e2e"; -import * as DateTime from "effect/DateTime"; - -import { T3_HOME } from "../e2e.config.ts"; -import { run } from "./shell.ts"; -import { runPromise, test, WEB } from "./t3.ts"; - -const rollout = (id: string, cwd: string, timestamp: string) => - [ - { timestamp, type: "session_meta", payload: { id, cwd } }, - { - timestamp, - type: "event_msg", - payload: { type: "user_message", message: `Work on ${NodePath.basename(cwd)}` }, - }, - { - timestamp, - type: "response_item", - payload: { - type: "message", - role: "assistant", - content: [{ type: "output_text", text: "Done." }], - }, - }, - ] - .map((record) => JSON.stringify(record)) - .join("\n"); - -test( - "The Welcome page lists only projects with conversations inside the import window", - WEB, - async ({ t3, app, screen }) => { - const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-scenario-window-")); - const codexHome = NodePath.join(root, "codex"); - const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json"); - const originalSettings = await NodeFSP.readFile(settingsPath, "utf8"); - try { - const now = await runPromise(DateTime.now); - for (const [project, ages] of [ - ["recent-app", [2, 45]], - ["archived-app", [60, 90]], - ] as const) { - const workspace = NodePath.join(root, project); - await NodeFSP.mkdir(workspace); - await runPromise(run("git", ["init", "--quiet"], { cwd: workspace })); - for (const ageDays of ages) { - const at = DateTime.subtract(now, { days: ageDays }); - const timestamp = DateTime.formatIso(at); - const seconds = DateTime.toEpochMillis(at) / 1000; - const id = `${project}-${ageDays}`; - const day = timestamp.slice(0, 10).split("-"); - const file = NodePath.join(codexHome, "sessions", ...day, `rollout-${id}.jsonl`); - await NodeFSP.mkdir(NodePath.dirname(file), { recursive: true }); - await NodeFSP.writeFile(file, rollout(id, workspace, timestamp)); - await NodeFSP.utimes(file, seconds, seconds); - } - } - const settings = JSON.parse(originalSettings); - settings.providerInstances.codex = { - ...settings.providerInstances.codex, - enabled: true, - config: { ...settings.providerInstances.codex.config, homePath: codexHome }, - }; - await NodeFSP.writeFile(settingsPath, JSON.stringify(settings)); - - await t3.open("/welcome"); - const reviewAll = screen.getByRole("button", /^Review all/); - await expect(reviewAll).toBeVisible({ timeout: 60_000 }); - await reviewAll.tap(); - await expect(screen.getByText("recent-app").first()).toBeVisible({ timeout: 60_000 }); - await app.screenshot("project-list"); - - await expect(screen.getByText("archived-app")).toHaveCount(0); - } finally { - await NodeFSP.writeFile(settingsPath, originalSettings); - await NodeFSP.rm(root, { recursive: true, force: true }); - } - }, -);