Skip to content
Closed
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
13 changes: 12 additions & 1 deletion apps/web/src/components/settings/SavedEnvironmentRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
RouteIcon,
} from "lucide-react";
import { useAtomValue } from "@effect/atom-react";
import { useNavigate } from "@tanstack/react-router";
import { useEffect, useEffectEvent, useState } from "react";
import {
AuthOrchestrationOperateScope,
AuthRelayWriteScope,
type EnvironmentId,
connectReachabilityHelpUrl,
Expand Down Expand Up @@ -55,7 +57,7 @@ import { useManagedTunnelUsage } from "~/cloud/managedRelayState";
import { useT3ConnectAccountPage } from "../clerk/T3ConnectAccountPages";
import { TunnelLimitAlert, TunnelUsageMeter } from "../cloud/TunnelUsage";
import { environmentCatalog } from "~/connection/catalog";
import { readEnvironmentScope } from "~/state/session";
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
import { type EnvironmentPresentation, useRelayEnvironmentDiscovery } from "~/state/environments";
import { APP_VERSION } from "~/branding";
import { useManagedPolicy } from "~/state/managedPolicy";
Expand Down Expand Up @@ -124,6 +126,10 @@ export function SavedBackendListRow({
const enabled = environment.entry.enabled && !unsupported;
const isConnected = environment.connection.phase === "connected";
const isRemoving = removingEnvironmentId === environmentId;
const navigate = useNavigate();
// Opens the Welcome page for this row's computer, which then scans that computer's history.
const canImportSessions =
useEnvironmentScope(environmentId, AuthOrchestrationOperateScope) && enabled && isConnected;
const errorTraceId = environment.connection.traceId;
const { copyToClipboard: copyTraceIdToClipboard } = useCopyToClipboard<{ traceId: string }>({
target: "trace ID",
Expand Down Expand Up @@ -418,6 +424,11 @@ export function SavedBackendListRow({
<RouteIcon />
{routesOpen ? "Hide routes" : "Routes"}
</MenuItem>
{canImportSessions ? (
<MenuItem onClick={() => void navigate({ to: "/welcome", search: { environmentId } })}>
Import sessions…
</MenuItem>
) : null}
{mcpUrl ? (
<MenuItem onClick={() => copyMcpUrl(mcpUrl, { url: mcpUrl })}>Copy MCP URL</MenuItem>
) : null}
Expand Down
46 changes: 46 additions & 0 deletions apps/web/src/onboarding/welcomePage.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
codexCardProvider,
codexNeedsSetup,
groupWelcomeAgents,
resolveWelcomeEnvironmentId,
turnedOnInstance,
welcomeOffersPhone,
} from "./welcomePage.logic";
Expand Down Expand Up @@ -263,3 +264,48 @@ describe("welcomeOffersPhone", () => {
expect(offers({ isPrimary: false })).toBe(false);
});
});

describe("resolveWelcomeEnvironmentId", () => {
const base = {
resumeEnvironmentId: undefined,
requestedEnvironmentId: undefined,
primaryEnvironmentId: "primary",
knownEnvironmentIds: ["primary", "remote", "other"],
};

it("sets up this computer by default", () => {
expect(resolveWelcomeEnvironmentId(base)).toBe("primary");
});

it("opens a connected computer that Settings asked for", () => {
expect(resolveWelcomeEnvironmentId({ ...base, requestedEnvironmentId: "remote" })).toBe(
"remote",
);
});

it("lets a ChatGPT sign-in return to the computer it set up", () => {
expect(
resolveWelcomeEnvironmentId({
...base,
resumeEnvironmentId: "other",
requestedEnvironmentId: "remote",
}),
).toBe("other");
});

it("ignores a computer the catalog does not know", () => {
expect(resolveWelcomeEnvironmentId({ ...base, requestedEnvironmentId: "gone" })).toBe(
"primary",
);
});

it("opens a connected computer without a primary one, as in the hosted app", () => {
expect(
resolveWelcomeEnvironmentId({
...base,
primaryEnvironmentId: null,
requestedEnvironmentId: "remote",
}),
).toBe("remote");
});
});
20 changes: 20 additions & 0 deletions apps/web/src/onboarding/welcomePage.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,23 @@ export function codexCardProvider(input: {
welcomeAgentState(provider, input.settings) === "checking";
return open ? provider : null;
}

/**
* The computer the Welcome page sets up. A ChatGPT sign-in returns to the computer it set up, and
* Settings opens the page for a connected computer; either id counts only once the catalog knows
* it, so an unknown one falls back to this computer.
*/
export function resolveWelcomeEnvironmentId<Id extends string>(input: {
readonly resumeEnvironmentId: Id | undefined;
readonly requestedEnvironmentId: Id | undefined;
readonly primaryEnvironmentId: Id | null;
readonly knownEnvironmentIds: ReadonlyArray<Id>;
}): Id | null {
const known = (id: Id | undefined) =>
id !== undefined && input.knownEnvironmentIds.includes(id) ? id : undefined;
return (
known(input.resumeEnvironmentId) ??
known(input.requestedEnvironmentId) ??
input.primaryEnvironmentId
);
}
26 changes: 20 additions & 6 deletions apps/web/src/routes/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Option from "effect/Option";
import { NoProjectsHero } from "../components/NoProjectsHero";
import { WelcomePage } from "../components/onboarding/WelcomePage";
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { resolveWelcomeEnvironmentId } from "../onboarding/welcomePage.logic";
import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";

const decodeEnvironmentId = Schema.decodeOption(EnvironmentId);
Expand All @@ -18,6 +19,14 @@ export const Route = createFileRoute("/welcome")({
throw redirect({ to: "/pair", replace: true });
}
},
// Settings → Environments opens the page for a connected computer to import its history.
validateSearch: (raw: Record<string, unknown>): { environmentId?: EnvironmentId } => {
const environmentId =
typeof raw.environmentId === "string"
? Option.getOrUndefined(decodeEnvironmentId(raw.environmentId))
: undefined;
return environmentId === undefined ? {} : { environmentId };
},
component: WelcomeRouteView,
});

Expand All @@ -28,15 +37,20 @@ function WelcomeRouteView() {
const resumeEnvironmentId = hash.startsWith("agents:")
? Option.getOrUndefined(decodeEnvironmentId(hash.slice("agents:".length)))
: undefined;
const requestedEnvironmentId = Route.useSearch({ select: (search) => search.environmentId });
const primaryEnvironmentId = usePrimaryEnvironmentId();
const { environments, isReady } = useEnvironments();
// Trust the id only once the catalog has it; an unknown computer falls back to this one.
const waitingForCatalog =
!isReady && (resumeEnvironmentId !== undefined || primaryEnvironmentId === null);
const resumeKnown =
resumeEnvironmentId !== undefined &&
environments.some((environment) => environment.environmentId === resumeEnvironmentId);
const environmentId = (resumeKnown ? resumeEnvironmentId : undefined) ?? primaryEnvironmentId;
!isReady &&
(resumeEnvironmentId !== undefined ||
requestedEnvironmentId !== undefined ||
primaryEnvironmentId === null);
const environmentId = resolveWelcomeEnvironmentId({
resumeEnvironmentId,
requestedEnvironmentId,
primaryEnvironmentId,
knownEnvironmentIds: environments.map((environment) => environment.environmentId),
});
// The root can remount this pending outlet after navigation; do not reopen setup.
const isWelcomeRoute = useLocation({ select: (location) => location.pathname === "/welcome" });
const [dismissed, setDismissed] = useState(false);
Expand Down
6 changes: 6 additions & 0 deletions docs/user/welcome-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and the phone app. Only an agent is needed to start chatting.
To see the page again, go to **Settings → About → Welcome page** and select
**Open**. Direct links, such as Settings, open normally before setup is done.

The page sets up the computer you are using. To import projects and sessions from
another connected computer, go to **Settings → Environments**, open that
computer's **⋯** menu and select **Import sessions…**. The Welcome page then
lists that computer's agents and its Claude Code, Codex, and Pi history. The
option needs a connected computer and a connection that can import projects.

The hosted app at app.t3.codes does not open the page. With no computer connected,
it asks you to sign in to T3 Connect, then to install T3 Code and run
`t3 connect` on your computer. From home, it adds compatible computers linked to your account and
Expand Down
Loading