The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): the composer send reads its own settings and draft instead of taking them from ChatView (#23095)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 21, 2026 at 14:25 UTC
beec3c8b30cecbd61383339cde42374282d1dee3
4 files changed
+265
-60
apps/web/src/components/ChatView.tsx
-7
@@ -2983,15 +2983,8 @@ export default function ChatView(props: ChatViewProps) {
2983
sendEnvMode,
2984
startFromOrigin,
2985
localCheckoutBranchMismatch,
2986
- settings,
2987
- clientSettingsHydrated,
2988
- serverConfig,
2989
- environmentById,
2986
logicalProjectEnvironments,
2987
providerInstanceEntries,
2992
- supportsAttachmentUploads,
2993
- referencedThreadContexts,
2994
- composerHasNonPromptContent,
2988
composerRef,
2989
composerDraftTarget,
2990
promptRef,
apps/web/src/components/chat/composerSend.logic.test.ts
new
+125
@@ -0,0 +1,125 @@
1
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3
+import { describe, expect, it } from "vite-plus/test";
4
+import { formatInlineContextReference } from "../../lib/composerContextReferences";
5
+import { threadContextRecord, threadContextReference } from "../../lib/composerContextRecords";
6
+import {
7
+ approvalRedirectNotice,
8
+ loadBalancingSendWarning,
9
+ multipleModelSendBlock,
10
+ referencedThreadContexts,
11
+} from "./composerSend.logic";
12
+
13
+const local = EnvironmentId.make("local");
14
+const remote = EnvironmentId.make("remote");
15
+const localThread = threadContextRecord(scopeThreadRef(local, ThreadId.make("a")), "Local");
16
+const remoteThread = threadContextRecord(scopeThreadRef(remote, ThreadId.make("b")), "Remote");
17
+
18
+describe("referencedThreadContexts", () => {
19
+ it("keeps only the attached threads the prompt still links", () => {
20
+ const prompt = `see ${formatInlineContextReference(threadContextReference(remoteThread))}`;
21
+ expect(
22
+ referencedThreadContexts({ prompt, threadContexts: [localThread, remoteThread] }),
23
+ ).toEqual([remoteThread]);
24
+ });
25
+});
26
+
27
+describe("loadBalancingSendWarning", () => {
28
+ it("asks the user to wait while resource checks run", () => {
29
+ expect(
30
+ loadBalancingSendWarning({
31
+ pending: true,
32
+ threadContexts: [localThread, remoteThread],
33
+ candidateEnvironmentIds: [],
34
+ }).title,
35
+ ).toBe("Checking machine resources");
36
+ });
37
+
38
+ it("blames the attached threads when no machine can read all of them", () => {
39
+ expect(
40
+ loadBalancingSendWarning({
41
+ pending: false,
42
+ threadContexts: [localThread, remoteThread],
43
+ candidateEnvironmentIds: [local, remote],
44
+ }).description,
45
+ ).toMatch(/No machine can read every attached thread/);
46
+ });
47
+
48
+ it("blames resources when one machine can read every attached thread", () => {
49
+ expect(
50
+ loadBalancingSendWarning({
51
+ pending: false,
52
+ threadContexts: [localThread],
53
+ candidateEnvironmentIds: [remote, local],
54
+ }).description,
55
+ ).toMatch(/No eligible machine has available resources/);
56
+ });
57
+});
58
+
59
+describe("multipleModelSendBlock", () => {
60
+ const ready = {
61
+ selectionCount: 2,
62
+ serverSupportsWorktreeBootstrap: true,
63
+ isLocalDraftThread: true,
64
+ isGitRepo: true,
65
+ branch: "main",
66
+ };
67
+
68
+ it("lets a new Git draft with a branch and models start", () => {
69
+ expect(multipleModelSendBlock(ready)).toBeNull();
70
+ });
71
+
72
+ it("asks for a server update before checking the draft", () => {
73
+ expect(
74
+ multipleModelSendBlock({
75
+ ...ready,
76
+ serverSupportsWorktreeBootstrap: false,
77
+ isGitRepo: false,
78
+ }),
79
+ ).toBe("server-outdated");
80
+ });
81
+
82
+ it.each([
83
+ { isLocalDraftThread: false },
84
+ { isGitRepo: false },
85
+ { branch: null },
86
+ { selectionCount: 0 },
87
+ ])("needs a new Git thread with a branch and models (%o)", (override) => {
88
+ expect(multipleModelSendBlock({ ...ready, ...override })).toBe("needs-new-git-thread");
89
+ });
90
+});
91
+
92
+describe("approvalRedirectNotice", () => {
93
+ const settled = {
94
+ draftChanged: false,
95
+ declined: true,
96
+ approvalResponding: false,
97
+ approvalArrived: false,
98
+ };
99
+
100
+ it("says the decline went through when the draft changed after it", () => {
101
+ expect(approvalRedirectNotice({ ...settled, draftChanged: true })).toBe(
102
+ "Approval declined. Your message changed, so it wasn't sent.",
103
+ );
104
+ expect(approvalRedirectNotice({ ...settled, draftChanged: true, declined: false })).toBe(
105
+ "Your message changed, so it wasn't sent.",
106
+ );
107
+ });
108
+
109
+ it("explains an approval already being answered", () => {
110
+ expect(
111
+ approvalRedirectNotice({ ...settled, declined: false, approvalResponding: true }),
112
+ ).toMatch(/already being answered/);
113
+ });
114
+
115
+ it("explains an approval that arrived during the decline", () => {
116
+ expect(approvalRedirectNotice({ ...settled, approvalArrived: true })).toMatch(
117
+ /Another approval arrived/,
118
+ );
119
+ });
120
+
121
+ it("stays quiet when the decline failed or the user left the thread", () => {
122
+ expect(approvalRedirectNotice({ ...settled, declined: false })).toBeNull();
123
+ expect(approvalRedirectNotice(settled)).toBeNull();
124
+ });
125
+});
apps/web/src/components/chat/composerSend.logic.ts
new
+81
@@ -0,0 +1,81 @@
1
+import type { EnvironmentId, ThreadContextRecord } from "@t3tools/contracts";
2
+import { collectInlineContextIds } from "../../lib/composerContextReferences";
3
+
4
+/** Attached threads the prompt still links to; replacing linked text leaves stale records. */
5
+export function referencedThreadContexts(draft: {
6
+ readonly prompt: string;
7
+ readonly threadContexts: ReadonlyArray<ThreadContextRecord>;
8
+}): ReadonlyArray<ThreadContextRecord> {
9
+ if (draft.threadContexts.length === 0) return [];
10
+ const referenced = new Set(collectInlineContextIds(draft.prompt));
11
+ return draft.threadContexts.filter((record) => referenced.has(record.contextId));
12
+}
13
+
14
+/** Why a send waits for the user to pick a machine when no machine was chosen automatically. */
15
+export function loadBalancingSendWarning(input: {
16
+ readonly pending: boolean;
17
+ readonly threadContexts: ReadonlyArray<ThreadContextRecord>;
18
+ readonly candidateEnvironmentIds: ReadonlyArray<EnvironmentId>;
19
+}) {
20
+ if (input.pending) {
21
+ return {
22
+ title: "Checking machine resources",
23
+ description: "Resource checks are still running. You can choose a machine in the composer.",
24
+ };
25
+ }
26
+ const noMachineReadsEveryThread =
27
+ input.threadContexts.length > 0 &&
28
+ !input.candidateEnvironmentIds.some((environmentId) =>
29
+ input.threadContexts.every((record) => record.environmentId === environmentId),
30
+ );
31
+ return {
32
+ title: "Choose a machine to continue",
33
+ description: noMachineReadsEveryThread
34
+ ? "No machine can read every attached thread. Choose a machine in the composer or remove the threads."
35
+ : "No eligible machine has available resources. Choose a machine in the composer to override.",
36
+ };
37
+}
38
+
39
+/**
40
+ * Why a multiple-model send cannot start: the server predates worktree bootstrap, or the
41
+ * draft is not a new thread on a Git branch with at least one model.
42
+ */
43
+export function multipleModelSendBlock(input: {
44
+ readonly selectionCount: number;
45
+ readonly serverSupportsWorktreeBootstrap: boolean;
46
+ readonly isLocalDraftThread: boolean;
47
+ readonly isGitRepo: boolean;
48
+ readonly branch: string | null;
49
+}): "server-outdated" | "needs-new-git-thread" | null {
50
+ if (!input.serverSupportsWorktreeBootstrap) return "server-outdated";
51
+ if (
52
+ !input.isLocalDraftThread ||
53
+ !input.isGitRepo ||
54
+ !input.branch ||
55
+ input.selectionCount === 0
56
+ ) {
57
+ return "needs-new-git-thread";
58
+ }
59
+ return null;
60
+}
61
+
62
+/** Why a message sent over pending approvals did not go out, or null to stop quietly. */
63
+export function approvalRedirectNotice(input: {
64
+ readonly draftChanged: boolean;
65
+ readonly declined: boolean;
66
+ readonly approvalResponding: boolean;
67
+ readonly approvalArrived: boolean;
68
+}): string | null {
69
+ if (input.draftChanged) {
70
+ return input.declined
71
+ ? "Approval declined. Your message changed, so it wasn't sent."
72
+ : "Your message changed, so it wasn't sent.";
73
+ }
74
+ if (input.approvalResponding) {
75
+ return "An approval is already being answered, so your message wasn't sent.";
76
+ }
77
+ if (input.declined && input.approvalArrived) {
78
+ return "Another approval arrived, so your message wasn't sent.";
79
+ }
80
+ return null;
81
+}
apps/web/src/components/chat/useComposerSend.ts
+59
-53
@@ -82,6 +82,14 @@ import {
82
import { environmentServerConfigsAtom } from "../../state/server";
83
import { threadEnvironment } from "../../state/threads";
84
import { runMobileComposerTransition } from "./draftHeroTransition";
85
+import { useClientSettingsHydrated, useEnvironmentSettings } from "../../hooks/useSettings";
86
+import { environmentPresentations } from "../../state/presentation";
87
+import {
88
+ approvalRedirectNotice,
89
+ loadBalancingSendWarning,
90
+ multipleModelSendBlock,
91
+ referencedThreadContexts,
92
+} from "./composerSend.logic";
93
import { usePlanFollowUpSend } from "./useProposedPlanSend";
94
import { useMultipleModelSend } from "./useMultipleModelSend";
95
import { type ComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch";
@@ -108,12 +116,11 @@ import {
116
prepareTurnAttachments,
117
restoreComposerDraft,
118
} from "./chatViewSend";
111
-import type { EnvironmentServerConfig } from "@t3tools/client-runtime/connection";
119
import type {
120
EnvironmentProject,
121
EnvironmentThreadShell,
122
} from "@t3tools/client-runtime/state/shell";
116
-import type { ThreadContextRecord, UnifiedSettings } from "@t3tools/contracts";
123
+import type { UnifiedSettings } from "@t3tools/contracts";
124
import type { Dispatch } from "react";
125
import type { ComposerThreadTarget } from "../../composerDraftStore";
126
import type { ProviderInstanceEntry } from "../../providerInstances";
@@ -122,7 +129,6 @@ import type { DraftSessionState } from "../../composerDraftStore";
129
import type { ComposerHandleRef } from "../../composerHandleContext";
130
import type { useLogicalProjectEnvironments } from "../../hooks/useLogicalProjectEnvironments";
131
import type { LatestProposedPlanState } from "../../session-logic";
125
-import type { EnvironmentPresentation } from "../../state/environments";
132
import type { useDraftEnvironmentRouting } from "./useDraftEnvironmentRouting";
133
import type { useLocalDispatchState } from "./useLocalDispatchState";
134
import type { usePendingThreadRequests } from "./usePendingThreadRequests";
@@ -133,6 +139,17 @@ import type { useWorktreeSetup } from "./useWorktreeSetup";
139
140
const ENVIRONMENT_UNAVAILABLE_SEND_TOAST_TRAIL_SIZE = 3;
141
142
+const selectPlanModeEnabled = (settings: UnifiedSettings) => settings.planModeEnabled;
143
+
144
+function readEnvironmentPresentation(environmentId: EnvironmentId) {
145
+ return appAtomRegistry.get(environmentPresentations.presentationsAtom).get(environmentId);
146
+}
147
+
148
+function draftHasNonPromptContent(target: ComposerThreadTarget) {
149
+ const draft = useComposerDraftStore.getState().getComposerDraft(target);
150
+ return draft ? composerDraftHasUserContent({ ...draft, prompt: "" }) : false;
151
+}
152
+
153
type PendingThreadRequests = ReturnType<typeof usePendingThreadRequests>;
154
type LocalDispatchState = ReturnType<typeof useLocalDispatchState>;
155
type DraftEnvironmentRouting = ReturnType<typeof useDraftEnvironmentRouting>;
@@ -163,15 +180,8 @@ interface ComposerSendInput {
180
readonly threadBranch: string;
181
readonly currentBranch: string;
182
} | null;
166
- readonly settings: UnifiedSettings;
167
- readonly clientSettingsHydrated: boolean;
168
- readonly serverConfig: EnvironmentServerConfig | null;
169
- readonly environmentById: ReadonlyMap<EnvironmentId, EnvironmentPresentation>;
183
readonly logicalProjectEnvironments: ReturnType<typeof useLogicalProjectEnvironments>;
184
readonly providerInstanceEntries: ReadonlyArray<ProviderInstanceEntry>;
172
- readonly supportsAttachmentUploads: boolean;
173
- readonly referencedThreadContexts: ReadonlyArray<ThreadContextRecord>;
174
- readonly composerHasNonPromptContent: boolean;
185
readonly composerRef: ComposerHandleRef;
186
readonly composerDraftTarget: ComposerThreadTarget;
187
readonly promptRef: { current: string };
@@ -257,15 +267,8 @@ export function useComposerSend(input: ComposerSendInput) {
267
sendEnvMode,
268
startFromOrigin,
269
localCheckoutBranchMismatch,
260
- settings,
261
- clientSettingsHydrated,
262
- serverConfig,
263
- environmentById,
270
logicalProjectEnvironments,
271
providerInstanceEntries,
266
- supportsAttachmentUploads,
267
- referencedThreadContexts,
268
- composerHasNonPromptContent,
272
composerRef,
273
composerDraftTarget,
274
promptRef,
@@ -316,6 +319,8 @@ export function useComposerSend(input: ComposerSendInput) {
319
} = input;
320
const handleNewThread = useNewThreadHandler();
321
const navigate = useNavigate();
322
+ const clientSettingsHydrated = useClientSettingsHydrated();
323
+ const planModeEnabled = useEnvironmentSettings(environmentId, selectPlanModeEnabled);
324
const startThreadTurn = useOrchestrationCommand(threadEnvironment.startTurn, {
325
reportFailure: false,
326
});
@@ -392,7 +397,7 @@ export function useComposerSend(input: ComposerSendInput) {
397
usageLimitsOffered &&
398
usageLimitsKey !== null &&
399
!directAnnotation &&
395
- !composerHasNonPromptContent &&
400
+ !draftHasNonPromptContent(composerDraftTarget) &&
401
isUsageLimitsCommand(promptRef.current)
402
) {
403
if (openUsageLimits()) {
@@ -429,21 +434,16 @@ export function useComposerSend(input: ComposerSendInput) {
434
return;
435
}
436
if (needsLoadBalancing) {
437
+ const draft = useComposerDraftStore.getState().getComposerDraft(composerDraftTarget);
438
toastManager.add({
439
type: "warning",
434
- title: loadBalancing.pending
435
- ? "Checking machine resources"
436
- : "Choose a machine to continue",
437
- description: loadBalancing.pending
438
- ? "Resource checks are still running. You can choose a machine in the composer."
439
- : referencedThreadContexts.length > 0 &&
440
- !logicalProjectEnvironments.some((candidate) =>
441
- referencedThreadContexts.every(
442
- (record) => record.environmentId === candidate.environmentId,
443
- ),
444
- )
445
- ? "No machine can read every attached thread. Choose a machine in the composer or remove the threads."
446
- : "No eligible machine has available resources. Choose a machine in the composer to override.",
440
+ ...loadBalancingSendWarning({
441
+ pending: loadBalancing.pending,
442
+ threadContexts: draft ? referencedThreadContexts(draft) : [],
443
+ candidateEnvironmentIds: logicalProjectEnvironments.map(
444
+ (candidate) => candidate.environmentId,
445
+ ),
446
+ }),
447
});
448
return;
449
}
@@ -475,20 +475,23 @@ export function useComposerSend(input: ComposerSendInput) {
475
return;
476
}
477
const multipleModelSelections = sendCtx.multipleModelSelections;
478
- if (
479
- multipleModelSelections !== null &&
480
- serverConfig?.environment.capabilities.requiredWorktreeBootstrap !== true
481
- ) {
478
+ const multipleModelBlock =
479
+ multipleModelSelections === null
480
+ ? null
481
+ : multipleModelSendBlock({
482
+ selectionCount: multipleModelSelections.length,
483
+ serverSupportsWorktreeBootstrap:
484
+ readEnvironmentPresentation(activeThread.environmentId)?.serverConfig?.environment
485
+ .capabilities.requiredWorktreeBootstrap === true,
486
+ isLocalDraftThread,
487
+ isGitRepo,
488
+ branch: activeThreadBranch,
489
+ });
490
+ if (multipleModelBlock === "server-outdated") {
491
setThreadError(activeThread.id, "Update this server before starting multiple models.");
492
return;
493
}
485
- if (
486
- multipleModelSelections !== null &&
487
- (!isLocalDraftThread ||
488
- !isGitRepo ||
489
- !activeThreadBranch ||
490
- multipleModelSelections.length === 0)
491
- ) {
494
+ if (multipleModelBlock === "needs-new-git-thread") {
495
toastManager.add(
496
stackedThreadToast({
497
type: "warning",
@@ -534,7 +537,9 @@ export function useComposerSend(input: ComposerSendInput) {
537
environmentId,
538
})[0];
539
if (strandedThread) {
537
- const owner = environmentById.get(strandedThread.environmentId)?.label ?? "its machine";
540
+ const owner =
541
+ readEnvironmentPresentation(strandedThread.environmentId)?.entry.target.label ??
542
+ "its machine";
543
toastManager.add(
544
stackedThreadToast({
545
type: "warning",
@@ -838,7 +843,7 @@ export function useComposerSend(input: ComposerSendInput) {
843
selections: multipleModelSelections ?? [],
844
providerInstanceEntries,
845
messageText: messageTextForSend,
841
- planModeEnabled: settings.planModeEnabled,
846
+ planModeEnabled,
847
interactionMode: sendInteractionMode,
848
})) {
849
if ("error" in resolved) {
@@ -860,7 +865,8 @@ export function useComposerSend(input: ComposerSendInput) {
865
const turnUsesAttachmentUploads =
866
composerFilesSnapshot.length > 0
867
? attachmentCapabilitiesBeforeUpload.supportsAttachmentUploads
863
- : supportsAttachmentUploads;
868
+ : readEnvironmentPresentation(environmentId)?.serverConfig?.environment.capabilities
869
+ .attachmentUploads === true;
870
if (turnUsesAttachmentUploads && composerAttachmentsSnapshot.length > 0) {
871
for (const attachment of composerAttachmentsSnapshot) {
872
const upload =
@@ -1001,16 +1007,16 @@ export function useComposerSend(input: ComposerSendInput) {
1007
setDockedDraftHeroThreadKey((currentThreadKey) =>
1008
currentThreadKey === activeThreadKey ? null : currentThreadKey,
1009
);
1004
- if (draftChanged || approvalResponding || (declined && approvalArrived)) {
1010
+ const notice = approvalRedirectNotice({
1011
+ draftChanged,
1012
+ declined,
1013
+ approvalResponding,
1014
+ approvalArrived,
1015
+ });
1016
+ if (notice !== null) {
1017
toastManager.add({
1018
type: "info",
1007
- title: draftChanged
1008
- ? declined
1009
- ? "Approval declined. Your message changed, so it wasn't sent."
1010
- : "Your message changed, so it wasn't sent."
1011
- : approvalResponding
1012
- ? "An approval is already being answered, so your message wasn't sent."
1013
- : "Another approval arrived, so your message wasn't sent.",
1019
+ title: notice,
1020
description: "Send again when it's ready.",
1021
});
1022
}