1
import { useAuth } from "@clerk/react";
2
import { useAtomValue } from "@effect/atom-react";
3
import type {
4
+ AgentSessionProjectCandidate,
5
EnvironmentId,
6
ProjectId,
7
ScopedProjectRef,
33
import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
34
import { useCompleteOnboarding } from "../../onboarding/firstRun";
35
import {
36
+ groupOnboardingProjects,
37
partitionOnboardingProjects,
38
onboardingProjectKey,
39
resolveOnboardingLandingProject,
40
resolveOnboardingProjectId,
41
+ type OnboardingProjectGroup,
42
} from "../../onboarding/projectImport.logic";
43
import {
44
getOnboardingProviderState,
62
import { getDriverOption } from "../settings/providerDriverMeta";
63
import { TerminalViewport } from "../ThreadTerminalDrawer";
64
import { CloudEnvironmentConnectRows } from "../cloud/CloudEnvironmentConnectList";
65
+import { ClaudeAI, OpenAI } from "../Icons";
66
import { T3Wordmark } from "../T3Wordmark";
67
import { Button } from "../ui/button";
68
import { Checkbox } from "../ui/checkbox";
75
import { Dialog, DialogHeader, DialogPopup, DialogTitle } from "../ui/dialog";
76
import { toastManager } from "../ui/toast";
77
import { cn } from "../../lib/utils";
78
+import { formatRelativeTime } from "../../timestampFormat";
79
80
/**
81
* First-run welcome wizard. Rendered over the workspace at `/welcome` on a
1013
),
1014
[scans],
1015
);
1011
- const selected = candidates.filter((candidate) =>
1012
- selectedPaths
1013
- ? selectedPaths.has(candidate.key)
1014
- : recent.some((item) => item.key === candidate.key),
1016
+ const selectedKeys = useMemo(
1017
+ () => selectedPaths ?? new Set(recent.map((candidate) => candidate.key)),
1018
+ [selectedPaths, recent],
1019
);
1020
+ const selected = candidates.filter((candidate) => selectedKeys.has(candidate.key));
1021
1022
const finishAfterImport = () => {
1023
const projectRef = resolveOnboardingLandingProject(
1181
title="Choose your projects"
1182
description="Import projects and conversations from your selected computers."
1183
>
1184
+ {candidates.length > 0 ? (
1185
+ <div className="mt-5 flex items-center justify-between gap-3 text-xs text-muted-foreground">
1186
+ <span role="status">
1187
+ {selected.length} of {candidates.length} selected
1188
+ </span>
1189
+ <div className="flex items-center gap-1">
1190
+ <Button
1191
+ variant="ghost"
1192
+ size="xs"
1193
+ disabled={isImporting || selected.length === candidates.length}
1194
+ onClick={() => setSelectedPaths(new Set(candidates.map((item) => item.key)))}
1195
+ >
1196
+ Select all
1197
+ </Button>
1198
+ <Button
1199
+ variant="ghost"
1200
+ size="xs"
1201
+ disabled={isImporting || selected.length === 0}
1202
+ onClick={() => setSelectedPaths(new Set())}
1203
+ >
1204
+ Select none
1205
+ </Button>
1206
+ </div>
1207
+ </div>
1208
+ ) : null}
1209
<ScrollArea
1210
scrollFade
1181
- className="mt-5 h-auto max-h-80 [&_[data-slot=scroll-area-scrollbar]]:opacity-100"
1211
+ className="mt-2 h-auto max-h-80 [&_[data-slot=scroll-area-scrollbar]]:opacity-100"
1212
>
1213
<div className="space-y-5 pr-3">
1214
{scans.map((scan) => {
1185
- const groupCandidates = candidates.filter(
1215
+ const scanCandidates = candidates.filter(
1216
(candidate) => candidate.environmentId === scan.environmentId,
1217
);
1218
const label =
1221
return (
1222
<fieldset
1223
key={scan.environmentId}
1194
- className="min-w-0 space-y-1.5"
1224
+ className="min-w-0 space-y-0.5"
1225
disabled={isImporting}
1226
>
1197
- <legend className="mb-2 text-sm font-medium">{label}</legend>
1227
+ {scans.length > 1 ? (
1228
+ <legend className="mb-2 text-sm font-medium">{label}</legend>
1229
+ ) : null}
1230
{scan.isPending && scan.data === null ? (
1231
<div className="flex items-center gap-2 py-3 text-sm text-muted-foreground">
1232
<Spinner className="size-4" />
1242
Retry
1243
</Button>
1244
</div>
1213
- ) : groupCandidates.length === 0 ? (
1245
+ ) : scanCandidates.length === 0 ? (
1246
<p className="py-2 text-sm text-muted-foreground">
1247
No existing Claude Code or Codex projects found.
1248
</p>
1252
{SCAN_LIMIT_MESSAGE}
1253
</p>
1254
) : null}
1223
- {groupCandidates.map((candidate) => (
1224
- <label
1225
- key={candidate.key}
1226
- className="flex cursor-pointer items-center gap-2.5 rounded-lg border border-border bg-background px-2.5 py-2 has-disabled:cursor-default"
1227
- >
1228
- <Checkbox
1229
- checked={selected.some((item) => item.key === candidate.key)}
1230
- onCheckedChange={(checked) => {
1231
- const next = new Set(selected.map((item) => item.key));
1232
- if (checked) next.add(candidate.key);
1233
- else next.delete(candidate.key);
1234
- setSelectedPaths(next);
1235
- }}
1236
- />
1237
- <Tooltip>
1238
- <TooltipTrigger
1239
- render={<span className="min-w-0 flex-1 truncate font-mono text-xs" />}
1240
- >
1241
- {candidate.path}
1242
- </TooltipTrigger>
1243
- <TooltipPopup className="max-w-96 break-all font-mono">
1244
- {candidate.path}
1245
- </TooltipPopup>
1246
- </Tooltip>
1247
- <span className="shrink-0 whitespace-nowrap text-[11px] text-muted-foreground">
1248
- {candidate.sources
1249
- .map((source) => (source === "claudeAgent" ? "Claude" : "Codex"))
1250
- .join(", ")}{" "}
1251
- · {candidate.threadCount} {candidate.threadCount === 1 ? "thread" : "threads"}
1252
- </span>
1253
- </label>
1254
- ))}
1255
+ <ImportCandidateList
1256
+ candidates={scanCandidates}
1257
+ selectedKeys={selectedKeys}
1258
+ onSelectionChange={setSelectedPaths}
1259
+ />
1260
</fieldset>
1261
);
1262
})}
1285
);
1286
}
1287
1288
+type ImportCandidate = AgentSessionProjectCandidate & {
1289
+ readonly environmentId: EnvironmentId;
1290
+ readonly key: string;
1291
+};
1292
+
1293
+/**
1294
+ * Repositories first, newest activity on top. Clones of one repository share
1295
+ * a group with a tri-state checkbox. Folders that are not git repositories
1296
+ * sit collapsed at the bottom so they stay reachable without adding noise.
1297
+ * Source icons appear only on repository rows so the columns stay still.
1298
+ */
1299
+function ImportCandidateList({
1300
+ candidates,
1301
+ selectedKeys,
1302
+ onSelectionChange,
1303
+}: {
1304
+ readonly candidates: ReadonlyArray<ImportCandidate>;
1305
+ readonly selectedKeys: ReadonlySet<string>;
1306
+ readonly onSelectionChange: (next: ReadonlySet<string>) => void;
1307
+}) {
1308
+ const { repositories, other } = useMemo(() => groupOnboardingProjects(candidates), [candidates]);
1309
+ const setKeys = (keys: ReadonlyArray<string>, checked: boolean) => {
1310
+ const next = new Set(selectedKeys);
1311
+ for (const key of keys) {
1312
+ if (checked) next.add(key);
1313
+ else next.delete(key);
1314
+ }
1315
+ onSelectionChange(next);
1316
+ };
1317
+ const otherSelected = other.filter((candidate) => selectedKeys.has(candidate.key)).length;
1318
+
1319
+ return (
1320
+ <>
1321
+ {repositories.map((group) => (
1322
+ <ImportRepositoryGroup
1323
+ key={group.key}
1324
+ group={group}
1325
+ selectedKeys={selectedKeys}
1326
+ onToggle={setKeys}
1327
+ />
1328
+ ))}
1329
+ {other.length > 0 ? (
1330
+ <Collapsible>
1331
+ <div className="flex items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-muted/40">
1332
+ <Checkbox
1333
+ checked={otherSelected === other.length}
1334
+ indeterminate={otherSelected > 0 && otherSelected < other.length}
1335
+ onCheckedChange={(checked) =>
1336
+ setKeys(
1337
+ other.map((candidate) => candidate.key),
1338
+ checked === true,
1339
+ )
1340
+ }
1341
+ />
1342
+ <CollapsibleTrigger className="group flex min-w-0 flex-1 items-center gap-1.5 text-left">
1343
+ <ChevronRightIcon className="size-3.5 shrink-0 text-muted-foreground transition-transform group-data-panel-open:rotate-90" />
1344
+ <span className="truncate text-sm text-muted-foreground">Other folders</span>
1345
+ <span className="ml-auto shrink-0 text-xs text-muted-foreground tabular-nums">
1346
+ {other.length} {other.length === 1 ? "folder" : "folders"}
1347
+ </span>
1348
+ </CollapsibleTrigger>
1349
+ </div>
1350
+ <CollapsiblePanel>
1351
+ {other.map((candidate) => (
1352
+ <ImportCandidateRow
1353
+ key={candidate.key}
1354
+ candidate={candidate}
1355
+ label={candidate.path}
1356
+ nested
1357
+ checked={selectedKeys.has(candidate.key)}
1358
+ onCheckedChange={(checked) => setKeys([candidate.key], checked)}
1359
+ />
1360
+ ))}
1361
+ </CollapsiblePanel>
1362
+ </Collapsible>
1363
+ ) : null}
1364
+ </>
1365
+ );
1366
+}
1367
+
1368
+function ImportRepositoryGroup({
1369
+ group,
1370
+ selectedKeys,
1371
+ onToggle,
1372
+}: {
1373
+ readonly group: OnboardingProjectGroup<ImportCandidate>;
1374
+ readonly selectedKeys: ReadonlySet<string>;
1375
+ readonly onToggle: (keys: ReadonlyArray<string>, checked: boolean) => void;
1376
+}) {
1377
+ const keys = group.candidates.map((candidate) => candidate.key);
1378
+ const selectedCount = keys.filter((key) => selectedKeys.has(key)).length;
1379
+ const single = group.candidates.length === 1;
1380
+ const only = group.candidates[0];
1381
+ if (single && only !== undefined) {
1382
+ return (
1383
+ <ImportCandidateRow
1384
+ candidate={only}
1385
+ label={group.label}
1386
+ {...(group.repository === null ? {} : { secondary: only.path })}
1387
+ checked={selectedKeys.has(only.key)}
1388
+ onCheckedChange={(checked) => onToggle([only.key], checked)}
1389
+ />
1390
+ );
1391
+ }
1392
+ return (
1393
+ <Collapsible defaultOpen>
1394
+ <div className="flex items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-muted/40">
1395
+ <Checkbox
1396
+ checked={selectedCount === keys.length}
1397
+ indeterminate={selectedCount > 0 && selectedCount < keys.length}
1398
+ onCheckedChange={(checked) => onToggle(keys, checked === true)}
1399
+ />
1400
+ <CollapsibleTrigger className="group flex min-w-0 flex-1 items-center gap-1.5 text-left">
1401
+ <ChevronRightIcon className="size-3.5 shrink-0 text-muted-foreground transition-transform group-data-panel-open:rotate-90" />
1402
+ <span className="truncate text-sm font-medium">{group.label}</span>
1403
+ <ImportRowMeta
1404
+ sources={[...new Set(group.candidates.flatMap((c) => c.sources))]}
1405
+ threadCount={group.threadCount}
1406
+ lastActiveAt={group.lastActiveAt}
1407
+ />
1408
+ </CollapsibleTrigger>
1409
+ </div>
1410
+ <CollapsiblePanel>
1411
+ {group.candidates.map((candidate) => (
1412
+ <ImportCandidateRow
1413
+ key={candidate.key}
1414
+ candidate={candidate}
1415
+ label={candidate.path}
1416
+ nested
1417
+ checked={selectedKeys.has(candidate.key)}
1418
+ onCheckedChange={(checked) => onToggle([candidate.key], checked)}
1419
+ />
1420
+ ))}
1421
+ </CollapsiblePanel>
1422
+ </Collapsible>
1423
+ );
1424
+}
1425
+
1426
+function ImportCandidateRow({
1427
+ candidate,
1428
+ label,
1429
+ secondary,
1430
+ nested = false,
1431
+ checked,
1432
+ onCheckedChange,
1433
+}: {
1434
+ readonly candidate: ImportCandidate;
1435
+ readonly label: string;
1436
+ readonly secondary?: string;
1437
+ readonly nested?: boolean;
1438
+ readonly checked: boolean;
1439
+ readonly onCheckedChange: (checked: boolean) => void;
1440
+}) {
1441
+ return (
1442
+ <label
1443
+ className={cn(
1444
+ "flex cursor-pointer items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-muted/40 has-disabled:cursor-default",
1445
+ nested && "pl-8",
1446
+ )}
1447
+ >
1448
+ <Checkbox checked={checked} onCheckedChange={(value) => onCheckedChange(value === true)} />
1449
+ <Tooltip>
1450
+ <TooltipTrigger
1451
+ render={<span className="flex min-w-0 flex-1 items-baseline gap-2 truncate" />}
1452
+ >
1453
+ <span className={cn("truncate", nested ? "font-mono text-xs" : "text-sm font-medium")}>
1454
+ {label}
1455
+ </span>
1456
+ {secondary !== undefined ? (
1457
+ <span className="truncate font-mono text-[11px] text-muted-foreground">
1458
+ {secondary}
1459
+ </span>
1460
+ ) : null}
1461
+ </TooltipTrigger>
1462
+ <TooltipPopup className="max-w-96 break-all font-mono">{candidate.path}</TooltipPopup>
1463
+ </Tooltip>
1464
+ <ImportRowMeta
1465
+ sources={nested ? null : candidate.sources}
1466
+ threadCount={candidate.threadCount}
1467
+ lastActiveAt={candidate.lastActiveAt}
1468
+ />
1469
+ </label>
1470
+ );
1471
+}
1472
+
1473
+/**
1474
+ * Trailing columns shared by every import row: source icons, thread count,
1475
+ * last activity. Each column has a fixed width and each icon has its own slot
1476
+ * so nothing shifts between rows that differ in sources or digit count.
1477
+ */
1478
+function ImportRowMeta({
1479
+ sources,
1480
+ threadCount,
1481
+ lastActiveAt,
1482
+}: {
1483
+ readonly sources: ReadonlyArray<"claudeAgent" | "codex"> | null;
1484
+ readonly threadCount: number;
1485
+ readonly lastActiveAt: string | null;
1486
+}) {
1487
+ const relative = lastActiveAt === null ? null : formatRelativeTime(lastActiveAt);
1488
+ // "just now" does not fit the fixed column, so collapse it.
1489
+ const age = relative === null ? "" : relative.suffix === null ? "now" : relative.value;
1490
+ return (
1491
+ <span className="ml-auto grid shrink-0 grid-cols-[1rem_1rem_2.5rem_2.25rem] items-center gap-x-1 text-xs text-muted-foreground tabular-nums">
1492
+ <span className="flex size-4 items-center justify-center">
1493
+ {sources?.includes("claudeAgent") ? (
1494
+ <ClaudeAI className="size-3" aria-label="Claude Code" />
1495
+ ) : null}
1496
+ </span>
1497
+ <span className="flex size-4 items-center justify-center">
1498
+ {sources?.includes("codex") ? <OpenAI className="size-3" aria-label="Codex" /> : null}
1499
+ </span>
1500
+ <span className="text-right">{threadCount}</span>
1501
+ <span className="text-right whitespace-nowrap">{age}</span>
1502
+ </span>
1503
+ );
1504
+}
1505
+
1506
// ── Shared bits ──────────────────────────────────────────────
1507
1508
function StepShell({