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, 14:30 UTC
fix(web): threads without a project start on the primary environment (#26301)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 22:06 UTC
9c6429d74b59c7a06fb7357526457d192a744a9f
6 files changed
+69
-15
apps/web/src/components/CommandPalette.tsx
+1
-3
@@ -622,9 +622,7 @@ function OpenCommandPaletteDialog(props: {
622
const currentProjectEnvironmentId =
623
activeThread?.environmentId ?? activeDraftThread?.environmentId ?? null;
624
const currentProjectId = activeThread?.projectId ?? activeDraftThread?.projectId ?? null;
625
- const scratchTargetEnvironmentId = scratchEnvironmentId(
626
- currentProjectEnvironmentId ?? primaryEnvironmentId,
627
- );
625
+ const scratchTargetEnvironmentId = scratchEnvironmentId(currentProjectEnvironmentId);
626
const supportsTriage = (environmentId: EnvironmentId | null) =>
627
environments.find((environment) => environment.environmentId === environmentId)?.serverConfig
628
?.environment.capabilities.triage === true;
apps/web/src/components/chat/DraftHeroHeadline.tsx
+3
-4
@@ -143,12 +143,11 @@ export function DraftHeroHeadline({
143
project.environmentId === activeProjectRef.environmentId &&
144
project.id === activeProjectRef.projectId,
145
) ?? null);
146
- const scratchTargetEnvironmentId = scratchEnvironmentId(
147
- activeProjectRef?.environmentId ?? primaryEnvironmentId,
148
- );
146
+ const scratchTargetEnvironmentId = scratchEnvironmentId(activeProjectRef?.environmentId ?? null);
147
const scratchWorkspaceRoot = scratchWorkspaceRootFor(scratchTargetEnvironmentId);
148
const isScratchDraft =
151
- activeProject !== null && isScratchProject(activeProject, scratchWorkspaceRoot);
149
+ activeProject !== null &&
150
+ isScratchProject(activeProject, scratchWorkspaceRootFor(activeProject.environmentId));
151
152
const pickerItems: readonly PickerItem[] = [
153
...menuEntries.map(({ group }) => ({ value: group.projectKey, label: group.displayName })),
apps/web/src/components/promptLinks/NewThreadLinkView.tsx
+1
-2
@@ -175,8 +175,7 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
175
};
176
177
const openScratchDraft = async () => {
178
- const environmentId =
179
- scratchEnvironmentId(lastActiveEnvironmentId()) ?? scratchEnvironmentId(null);
178
+ const environmentId = scratchEnvironmentId(lastActiveEnvironmentId());
179
const project = environmentId === null ? null : await openScratchProject(environmentId);
180
if (project === null) {
181
setState({
apps/web/src/hooks/useScratchProject.test.ts
new
+49
@@ -0,0 +1,49 @@
1
+import type { EnvironmentId } from "@t3tools/contracts";
2
+import { AtomRegistry } from "effect/reactivity";
3
+import { describe, expect, it } from "vite-plus/test";
4
+
5
+import { createScratchProjectActions } from "./useScratchProject";
6
+
7
+const local = "local" as EnvironmentId;
8
+const remote = "remote" as EnvironmentId;
9
+const other = "other" as EnvironmentId;
10
+
11
+function scratchEnvironment(environmentId: EnvironmentId, scratchWorkspaceRoot: string | null) {
12
+ return {
13
+ environmentId,
14
+ connection: { phase: "connected" },
15
+ serverConfig: { scratchWorkspaceRoot },
16
+ } as never;
17
+}
18
+
19
+function actions(
20
+ primary: EnvironmentId | null,
21
+ localRoot: string | null,
22
+ remoteRoot: string | null = "/remote/scratch",
23
+) {
24
+ const environments = [
25
+ scratchEnvironment(local, localRoot),
26
+ scratchEnvironment(remote, remoteRoot),
27
+ scratchEnvironment(other, "/other/scratch"),
28
+ ];
29
+ return createScratchProjectActions({
30
+ environments: () => environments,
31
+ primaryEnvironmentId: () => primary,
32
+ registry: AtomRegistry.make(),
33
+ handleNewThread: async () => null,
34
+ });
35
+}
36
+
37
+describe("scratchEnvironmentId", () => {
38
+ it("prefers the primary environment over the one on screen", () => {
39
+ expect(actions(local, "/local/scratch").scratchEnvironmentId(remote)).toBe(local);
40
+ expect(actions(local, "/local/scratch").scratchEnvironmentId(null)).toBe(local);
41
+ });
42
+
43
+ it("falls back when the primary environment offers no scratch root", () => {
44
+ expect(actions(local, null).scratchEnvironmentId(remote)).toBe(remote);
45
+ expect(actions(null, null).scratchEnvironmentId(remote)).toBe(remote);
46
+ expect(actions(null, null, null).scratchEnvironmentId(remote)).toBe(other);
47
+ expect(actions(local, null).scratchEnvironmentId(null)).toBeNull();
48
+ });
49
+});
apps/web/src/hooks/useScratchProject.ts
+13
-3
@@ -12,7 +12,11 @@ import type { AtomRegistry } from "effect/reactivity";
12
import { useContext } from "react";
13
14
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
15
-import { type EnvironmentPresentation, useEnvironments } from "~/state/environments";
15
+import {
16
+ type EnvironmentPresentation,
17
+ useEnvironments,
18
+ usePrimaryEnvironmentId,
19
+} from "~/state/environments";
20
import { projectEnvironment } from "~/state/projects";
21
import { type NewThreadHandler, useNewThreadHandler } from "./useHandleNewThread";
22
@@ -32,6 +36,7 @@ type ScratchEnvironment = Pick<EnvironmentPresentation, "connection" | "serverCo
36
37
export function createScratchProjectActions(input: {
38
readonly environments: () => Iterable<ScratchEnvironment>;
39
+ readonly primaryEnvironmentId: () => EnvironmentId | null;
40
readonly registry: AtomRegistry.AtomRegistry;
41
readonly handleNewThread: NewThreadHandler;
42
}) {
@@ -43,8 +48,11 @@ export function createScratchProjectActions(input: {
48
return availableScratchWorkspaceRoot(environment?.connection.phase, environment?.serverConfig);
49
};
50
46
- const scratchEnvironmentId = (current: EnvironmentId | null): EnvironmentId | null => {
47
- if (current !== null) return scratchWorkspaceRootFor(current) !== null ? current : null;
51
+ // The primary (local) environment wins; `fallback` only applies when it offers no scratch root.
52
+ const scratchEnvironmentId = (fallback: EnvironmentId | null): EnvironmentId | null => {
53
+ const primary = input.primaryEnvironmentId();
54
+ if (primary !== null && scratchWorkspaceRootFor(primary) !== null) return primary;
55
+ if (fallback !== null && scratchWorkspaceRootFor(fallback) !== null) return fallback;
56
const offering = [...input.environments()].filter(
57
(entry) => scratchWorkspaceRootFor(entry.environmentId) !== null,
58
);
@@ -85,10 +93,12 @@ export function createScratchProjectActions(input: {
93
94
export function useScratchProject() {
95
const { environments } = useEnvironments();
96
+ const primaryEnvironmentId = usePrimaryEnvironmentId();
97
const registry = useContext(RegistryContext);
98
const handleNewThread = useNewThreadHandler();
99
return createScratchProjectActions({
100
environments: () => environments,
101
+ primaryEnvironmentId: () => primaryEnvironmentId,
102
registry,
103
handleNewThread,
104
});
apps/web/src/shortcuts/chatRouteCommands.ts
+2
-3
@@ -39,6 +39,7 @@ export function installChatRouteCommands(router: AnyRouter): () => void {
39
[...appAtomRegistry.get(environmentPresentations.presentationsAtom)].map(
40
([environmentId, presentation]) => ({ ...presentation, environmentId }),
41
),
42
+ primaryEnvironmentId: () => appAtomRegistry.get(primaryEnvironmentIdAtom),
43
registry: appAtomRegistry,
44
handleNewThread,
45
});
@@ -109,9 +110,7 @@ export function installChatRouteCommands(router: AnyRouter): () => void {
110
"chat.newWithoutProject": (event) => {
111
const { activeThread, activeDraftThread } = readThreadContext();
112
const environmentId = scratch.scratchEnvironmentId(
112
- activeThread?.environmentId ??
113
- activeDraftThread?.environmentId ??
114
- appAtomRegistry.get(primaryEnvironmentIdAtom),
113
+ activeThread?.environmentId ?? activeDraftThread?.environmentId ?? null,
114
);
115
if (environmentId === null) return;
116
claim(event);