@devries-cameron20 / t3code Mirror · read-only / commits / 62ba72fa15
Fork 0

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 21, 16:00 UTC

fix(web): onboarding rechecks an agent when its install command finishes (#36477)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Artem committed Nov 14, 2026 at 07:19 UTC 62ba72fa15441050469740a51a19b45a8b1085c0
2 files changed +98 -2
apps/web/src/components/onboarding/WelcomePage.import.browser.test.tsx
+73 -2
@@ -4,6 +4,7 @@ import {
4 AuthOrchestrationReadScope,
5 AuthRelayReadScope,
6 AuthRelayWriteScope,
7 + AuthTerminalOperateScope,
8 EnvironmentId,
9 ProjectId,
10 ProviderDriverKind,
@@ -47,6 +48,10 @@ const state = vi.hoisted(() => ({
48 refreshLinkState: vi.fn(),
49 scanError: null as string | null,
50 scanPending: false,
51 + runningTerminalIds: null as unknown,
52 + openTerminal: vi.fn(),
53 + writeTerminal: vi.fn(),
54 + closeTerminal: vi.fn(),
55 }));
56
57 vi.mock(import("@t3tools/client-runtime/state/session"), async (original) => {
@@ -148,10 +153,41 @@ vi.mock(import("../../onboarding/useProjectScans"), async (original) => {
153 },
154 };
155 });
156 +vi.mock(import("../../state/terminal"), async (original) => {
157 + const actual = await original();
158 + return {
159 + ...actual,
160 + terminalEnvironment: {
161 + ...actual.terminalEnvironment,
162 + open: "openTerminal",
163 + write: "writeTerminal",
164 + close: "closeTerminal",
165 + } as never,
166 + };
167 +});
168 +vi.mock(import("../../state/terminalSessions"), async (original) => {
169 + const { useAtomValue } = await import("@effect/atom-react");
170 + return {
171 + ...(await original()),
172 + useThreadRunningTerminalIds: (() =>
173 + useAtomValue(state.runningTerminalIds as Atom.Atom<ReadonlyArray<string>>)) as never,
174 + };
175 +});
176 +vi.mock(import("../ThreadTerminalDrawer"), async (original) => ({
177 + ...(await original()),
178 + TerminalViewport: () => <div />,
179 +}));
180 vi.mock(import("../../state/use-atom-command"), async (original) => ({
181 ...(await original()),
153 - useAtomCommand: ((command: "createProject" | "importThreads" | "refreshProviders") =>
154 - state[command]) as never,
182 + useAtomCommand: ((
183 + command:
184 + | "createProject"
185 + | "importThreads"
186 + | "refreshProviders"
187 + | "openTerminal"
188 + | "writeTerminal"
189 + | "closeTerminal",
190 + ) => state[command]) as never,
191 }));
192
193 import { welcomeImportSelectionKey } from "../../onboarding/welcomeState";
@@ -327,6 +363,10 @@ function setup() {
363 state.refreshLinkState.mockReset();
364 state.scanError = null;
365 state.scanPending = false;
366 + state.runningTerminalIds = Atom.make<ReadonlyArray<string>>([]).pipe(Atom.keepAlive);
367 + for (const command of [state.openTerminal, state.writeTerminal, state.closeTerminal]) {
368 + command.mockReset().mockResolvedValue(AsyncResult.success(undefined));
369 + }
370 localStorage.removeItem(welcomeImportSelectionKey(primaryId));
371 return now;
372 }
@@ -625,6 +665,37 @@ it("offers Update for a signed-in agent whose version is broken, and keeps Start
665 expect(button("Import 2 projects and start").disabled).toBe(true);
666 });
667
668 +it("checks an agent again once its install command finishes in the setup terminal", async () => {
669 + using _now = setup();
670 + appAtomRegistry.set(
671 + sessionAtom(primaryId),
672 + AsyncResult.success(session([AuthOrchestrationOperateScope, AuthTerminalOperateScope])),
673 + );
674 + appAtomRegistry.set(state.config as Atom.Writable<unknown>, {
675 + cwd: "/Users/dev",
676 + environment: { platform: { os: "darwin" } },
677 + keybindings: [],
678 + settings: { providerInstances: {}, projectSettingsOverrides: {} },
679 + });
680 + appAtomRegistry.set(state.providers as Atom.Writable<ReadonlyArray<ServerProvider>>, [
681 + { ...readyClaude, installed: false, status: "error", auth: { status: "unknown" } },
682 + ]);
683 + await using _screen = await mountWelcome();
684 + await vi.waitFor(() => button("Install"));
685 + await click("Install");
686 + await vi.waitFor(() => expect(state.writeTerminal).toHaveBeenCalledOnce());
687 + const { terminalId } = state.openTerminal.mock.calls[0]![0].input;
688 + const runningTerminalIds = state.runningTerminalIds as Atom.Writable<ReadonlyArray<string>>;
689 + const recheck = { environmentId: primaryId, input: { instanceId: readyClaude.instanceId } };
690 +
691 + await act(async () => appAtomRegistry.set(runningTerminalIds, [terminalId]));
692 + expect(state.refreshProviders).not.toHaveBeenCalledWith(recheck);
693 + // The shell stays open at its prompt after the install, so only the command exits.
694 + await act(async () => appAtomRegistry.set(runningTerminalIds, []));
695 + expect(state.refreshProviders).toHaveBeenCalledWith(recheck);
696 + expect(state.closeTerminal).not.toHaveBeenCalled();
697 +});
698 +
699 it("keeps an import opt-out on the page when storage cannot save it", async () => {
700 using _now = setup();
701 await using _screen = await mountWelcome();
apps/web/src/components/onboarding/WelcomePage.tsx
+25
@@ -94,6 +94,7 @@ import {
94 useEnvironmentsWithScope,
95 } from "../../state/session";
96 import { terminalEnvironment } from "../../state/terminal";
97 +import { useThreadRunningTerminalIds } from "../../state/terminalSessions";
98 import { useAtomCommand } from "../../state/use-atom-command";
99 import { getProviderSummary } from "../settings/providerStatus";
100 import { AddProviderInstanceDialog } from "../settings/AddProviderInstanceDialog";
@@ -696,6 +697,12 @@ function AgentsSection({
697 <AgentInstallTerminal
698 key={`${terminalSession.environmentId}:${terminalSession.providerInstanceId}:${terminalSession.driver}`}
699 session={terminalSession}
700 + onCommandFinished={() =>
701 + void refreshProviders({
702 + environmentId,
703 + input: { instanceId: terminalSession.providerInstanceId },
704 + })
705 + }
706 onClose={() => {
707 setTerminalSession(null);
708 void refreshProviders({ environmentId, input: {} });
@@ -1201,9 +1208,11 @@ function AgentRow({
1208
1209 function AgentInstallTerminal({
1210 session,
1211 + onCommandFinished,
1212 onClose,
1213 }: {
1214 readonly session: AgentTerminalSession;
1215 + readonly onCommandFinished: () => void;
1216 readonly onClose: () => void;
1217 }) {
1218 const { command, cwd, driver, environmentId, keybindings, providerInstanceId } = session;
@@ -1226,6 +1235,22 @@ function AgentInstallTerminal({
1235 "preparing" | "ready" | "openFailed" | "writeFailed"
1236 >("preparing");
1237 const terminalReady = setupState === "ready" || setupState === "writeFailed";
1238 + const commandRunning = useThreadRunningTerminalIds({
1239 + environmentId,
1240 + threadId: AGENT_ONBOARDING_THREAD_ID,
1241 + }).includes(terminalId);
1242 + const commandStartedRef = useRef(false);
1243 + const handleCommandFinished = useEffectEvent(onCommandFinished);
1244 +
1245 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the shell stays open after an install or sign-in, so its command exiting is the only signal to check the agent again
1246 + useEffect(() => {
1247 + if (commandRunning) {
1248 + commandStartedRef.current = true;
1249 + } else if (commandStartedRef.current) {
1250 + commandStartedRef.current = false;
1251 + handleCommandFinished();
1252 + }
1253 + }, [commandRunning]);
1254
1255 // StrictMode can finish a cancelled open after replacement setup; it must not close or pre-type into that
1256 // session.