Skip to content

Commit 65c9f07

Browse files
t3dotggclaude
andcommitted
fix(web): read new-thread defaults from the primary environment
The "New threads" default (local vs. new worktree) and "start from origin" are stored in the server-side settings.json, but the settings UI only ever writes to the primary environment's settings. New-thread code paths read the setting from the thread's own environment, so threads created on remote environments always fell back to the decoded defaults ("local" mode on the current branch) no matter what the user picked. Read the defaults from the primary server settings everywhere they seed new drafts: useNewThreadHandler, the sidebar's per-project new-thread seeding, and ChatView's env-mode/start-from-origin resolution. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 32c6012 commit 65c9f07

3 files changed

Lines changed: 27 additions & 23 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ import { useEnvironmentQuery } from "../state/query";
188188
import {
189189
primaryServerAvailableEditorsAtom,
190190
primaryServerKeybindingsAtom,
191+
primaryServerSettingsAtom,
191192
serverEnvironment,
192193
} from "../state/server";
193194
import { terminalEnvironment } from "../state/terminal";
@@ -1139,6 +1140,10 @@ function ChatViewContent(props: ChatViewProps) {
11391140
(store) => store.threadLastVisitedAtById[routeThreadKey],
11401141
);
11411142
const settings = useEnvironmentSettings(environmentId);
1143+
// New-thread defaults live in the primary environment's settings.json (the
1144+
// settings UI never writes to remote environments), so read them from the
1145+
// primary server rather than the thread's environment.
1146+
const primaryServerSettings = useAtomValue(primaryServerSettingsAtom);
11421147
const setStickyComposerModelSelection = useComposerDraftStore(
11431148
(store) => store.setStickyModelSelection,
11441149
);
@@ -3734,7 +3739,7 @@ function ChatViewContent(props: ChatViewProps) {
37343739
? (draftThread?.startFromOrigin ?? false)
37353740
: canOverrideServerThreadEnvMode
37363741
? (pendingServerThreadStartFromOriginByThreadId[activeThread?.id ?? ""] ??
3737-
settings.newWorktreesStartFromOrigin)
3742+
primaryServerSettings.newWorktreesStartFromOrigin)
37383743
: false;
37393744
const sendEnvMode = resolveSendEnvMode({
37403745
requestedEnvMode: envMode,
@@ -5023,7 +5028,7 @@ function ChatViewContent(props: ChatViewProps) {
50235028
envMode: mode,
50245029
startFromOrigin: resolveNewDraftStartFromOrigin({
50255030
envMode: mode,
5026-
newWorktreesStartFromOrigin: settings.newWorktreesStartFromOrigin,
5031+
newWorktreesStartFromOrigin: primaryServerSettings.newWorktreesStartFromOrigin,
50275032
}),
50285033
...(mode === "worktree" && draftThread?.worktreePath ? { worktreePath: null } : {}),
50295034
});
@@ -5035,7 +5040,7 @@ function ChatViewContent(props: ChatViewProps) {
50355040
composerDraftTarget,
50365041
draftThread?.worktreePath,
50375042
isLocalDraftThread,
5038-
settings.newWorktreesStartFromOrigin,
5043+
primaryServerSettings.newWorktreesStartFromOrigin,
50395044
setPendingServerThreadEnvMode,
50405045
scheduleComposerFocus,
50415046
setDraftThreadContext,

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { restrictToFirstScrollableAncestor, restrictToVerticalAxis } from "@dnd-
4242
import { CSS } from "@dnd-kit/utilities";
4343
import {
4444
type ContextMenuItem,
45-
DEFAULT_SERVER_SETTINGS,
4645
ProjectId,
4746
type ScopedThreadRef,
4847
type ResolvedKeybindingsConfig,
@@ -80,7 +79,6 @@ import {
8079
readThreadShell,
8180
useProject,
8281
useProjects,
83-
useServerConfigs,
8482
useThreadShells,
8583
useThreadShellsForProjectRefs,
8684
} from "../state/entities";
@@ -202,7 +200,7 @@ import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
202200
import { useIsMobile } from "~/hooks/useMediaQuery";
203201
import { CommandDialogTrigger } from "./ui/command";
204202
import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";
205-
import { primaryServerKeybindingsAtom } from "../state/server";
203+
import { primaryServerKeybindingsAtom, primaryServerSettingsAtom } from "../state/server";
206204
import {
207205
derivePhysicalProjectKey,
208206
deriveProjectGroupingOverrideKey,
@@ -1106,7 +1104,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
11061104
(settings) => settings.confirmThreadArchive,
11071105
);
11081106
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
1109-
const serverConfigs = useServerConfigs();
1107+
const primaryServerSettings = useAtomValue(primaryServerSettingsAtom);
11101108
const deleteProject = useAtomCommand(projectEnvironment.delete, {
11111109
reportFailure: false,
11121110
});
@@ -1894,10 +1892,10 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
18941892
: null;
18951893
const seedContext = resolveSidebarNewThreadSeedContext({
18961894
projectId: member.id,
1895+
// The default env mode is a user preference stored on the primary
1896+
// environment's settings.json; remote environments never carry it.
18971897
defaultEnvMode: resolveSidebarNewThreadEnvMode({
1898-
defaultEnvMode:
1899-
serverConfigs.get(member.environmentId)?.settings.defaultThreadEnvMode ??
1900-
DEFAULT_SERVER_SETTINGS.defaultThreadEnvMode,
1898+
defaultEnvMode: primaryServerSettings.defaultThreadEnvMode,
19011899
}),
19021900
activeThread:
19031901
currentActiveThread && currentActiveThread.projectId === member.id
@@ -1946,7 +1944,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
19461944
}
19471945
})();
19481946
},
1949-
[handleNewThread, isMobile, router, serverConfigs, setOpenMobile],
1947+
[handleNewThread, isMobile, primaryServerSettings.defaultThreadEnvMode, router, setOpenMobile],
19501948
);
19511949

19521950
const handleCreateThreadClick = useCallback(

‎apps/web/src/hooks/useHandleNewThread.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
import { useAtomValue } from "@effect/atom-react";
12
import {
23
scopedProjectKey,
34
scopeProjectRef,
45
scopeThreadRef,
56
} from "@t3tools/client-runtime/environment";
6-
import {
7-
DEFAULT_RUNTIME_MODE,
8-
DEFAULT_SERVER_SETTINGS,
9-
type ScopedProjectRef,
10-
} from "@t3tools/contracts";
7+
import { DEFAULT_RUNTIME_MODE, type ScopedProjectRef } from "@t3tools/contracts";
118
import { useParams, useRouter } from "@tanstack/react-router";
129
import { useCallback, useMemo } from "react";
1310
import {
@@ -23,15 +20,21 @@ import {
2320
getProjectOrderKey,
2421
selectProjectGroupingSettings,
2522
} from "../logicalProject";
26-
import { readThreadShell, useProjects, useServerConfigs, useThread } from "../state/entities";
23+
import { readThreadShell, useProjects, useThread } from "../state/entities";
2724
import { resolveNewDraftStartFromOrigin } from "../lib/chatThreadActions";
25+
import { primaryServerSettingsAtom } from "../state/server";
2826
import { resolveThreadRouteTarget } from "../threadRoutes";
2927
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
3028
import { useClientSettings } from "./useSettings";
3129

3230
export function useNewThreadHandler() {
3331
const projects = useProjects();
34-
const serverConfigs = useServerConfigs();
32+
// New-thread defaults are a user preference, and the settings UI only ever
33+
// edits the primary environment's settings.json. Reading the target
34+
// environment's own settings here would silently reset remote projects to
35+
// the decoded defaults ("local" mode, current branch), since nothing can
36+
// set those values on a remote server.
37+
const primaryServerSettings = useAtomValue(primaryServerSettingsAtom);
3538
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
3639
const router = useRouter();
3740
const getCurrentRouteTarget = useCallback(() => {
@@ -64,8 +67,6 @@ export function useNewThreadHandler() {
6467
candidate.id === projectRef.projectId &&
6568
candidate.environmentId === projectRef.environmentId,
6669
);
67-
const environmentSettings =
68-
serverConfigs.get(projectRef.environmentId)?.settings ?? DEFAULT_SERVER_SETTINGS;
6970
const logicalProjectKey = project
7071
? deriveLogicalProjectKeyFromSettings(project, projectGroupingSettings)
7172
: scopedProjectKey(projectRef);
@@ -161,7 +162,7 @@ export function useNewThreadHandler() {
161162
const draftId = newDraftId();
162163
const threadId = newThreadId();
163164
const createdAt = new Date().toISOString();
164-
const initialEnvMode = options?.envMode ?? environmentSettings.defaultThreadEnvMode;
165+
const initialEnvMode = options?.envMode ?? primaryServerSettings.defaultThreadEnvMode;
165166
return (async () => {
166167
setLogicalProjectDraftThreadId(logicalProjectKey, projectRef, draftId, {
167168
threadId,
@@ -173,7 +174,7 @@ export function useNewThreadHandler() {
173174
options?.startFromOrigin ??
174175
resolveNewDraftStartFromOrigin({
175176
envMode: initialEnvMode,
176-
newWorktreesStartFromOrigin: environmentSettings.newWorktreesStartFromOrigin,
177+
newWorktreesStartFromOrigin: primaryServerSettings.newWorktreesStartFromOrigin,
177178
}),
178179
runtimeMode: DEFAULT_RUNTIME_MODE,
179180
});
@@ -186,7 +187,7 @@ export function useNewThreadHandler() {
186187
});
187188
})();
188189
},
189-
[getCurrentRouteTarget, projectGroupingSettings, projects, router, serverConfigs],
190+
[getCurrentRouteTarget, primaryServerSettings, projectGroupingSettings, projects, router],
190191
);
191192
}
192193

0 commit comments

Comments
 (0)