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, 09:45 UTC
fix(web): Cmd+Enter on an edited queued message steers it into the running turn (#37507)
Co-authored-by: claude-opus-5.5 <me+ai@stefanmirea.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Stefan Mirea committed
Nov 16, 2026 at 06:24 UTC
1b84e72a6dd7abbeaacd3dc10fc1f6aedeff9a1d
4 files changed
+110
-4
apps/web/src/components/chat/ChatComposer.tsx
+5
-2
@@ -2225,14 +2225,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2225
});
2226
const handleSubmitMessage = (event: React.MouseEvent<HTMLButtonElement>) => {
2227
event.preventDefault();
2228
+ const running = phase === "running" || phase === "connecting";
2229
+ const alternateModifier = event.metaKey || event.ctrlKey;
2230
submitComposer(
2231
event,
2232
resolveComposerDispatchMode({
2231
- running: phase === "running" || phase === "connecting",
2232
- alternateModifier: event.metaKey || event.ctrlKey,
2233
+ running,
2234
+ alternateModifier,
2235
activeTurnDefault: followUpBehavior,
2236
canSteer,
2237
}),
2238
+ running && alternateModifier ? "alternate" : undefined,
2239
);
2240
};
2241
const handleSubmitMessageStable = useStableCallback(handleSubmitMessage);
apps/web/src/components/chat/useComposerSend.ts
+1
@@ -660,6 +660,7 @@ export function useComposerSend(input: ComposerSendInput) {
660
replyTo,
661
},
662
setThreadError,
663
+ { dispatchMode, submissionIntent },
664
);
665
return;
666
}
apps/web/src/components/chat/useQueuedRunEdit.browser.test.tsx
+65
-2
@@ -33,12 +33,15 @@ import { readAttachmentUpload, useAttachmentUploadStore } from "../../lib/attach
33
interface RunStatus {
34
readonly id: RunId;
35
readonly status: string;
36
+ readonly activeAttemptId?: string;
37
}
38
39
const mocks = await vi.hoisted(async () => {
40
const { Atom } = await import("effect/reactivity");
41
return {
42
editQueuedRun: vi.fn<(value: unknown) => Promise<{ readonly _tag: "Success" | "Failure" }>>(),
43
+ promoteQueuedRun: vi.fn<(value: unknown) => Promise<{ readonly _tag: "Success" }>>(),
44
+ promoteCommand: {},
45
// The projection's runs per thread, written by each test to stand in for the server.
46
threadRuns: Atom.family((_key: string) =>
47
Atom.make<ReadonlyArray<RunStatus> | null>(null).pipe(Atom.keepAlive),
@@ -47,7 +50,8 @@ const mocks = await vi.hoisted(async () => {
50
});
51
52
vi.mock("../../state/use-atom-command", () => ({
50
- useAtomCommand: () => mocks.editQueuedRun,
53
+ useAtomCommand: (command: unknown) =>
54
+ command === mocks.promoteCommand ? mocks.promoteQueuedRun : mocks.editQueuedRun,
55
}));
56
57
vi.mock("../../hooks/useSettings", () => ({
@@ -63,13 +67,35 @@ vi.mock("../../state/threads", async () => {
67
threadEnvironment: {
68
snapshotAtom: () => Atom.make(null),
69
editQueuedRun: {},
70
+ promoteQueuedRun: mocks.promoteCommand,
71
},
72
environmentThreadDetails: {
73
statusAtom: () => Atom.make("ready"),
74
quietThreadAtom: (ref: ScopedThreadRef) =>
75
Atom.make((get) => {
76
const runs = get(mocks.threadRuns(key(ref)));
72
- return runs === null ? null : { projection: { runs } };
77
+ if (runs === null) return null;
78
+ // A Claude-like session whose running turn takes steering.
79
+ return {
80
+ projection: {
81
+ thread: { id: ref.threadId, activeProviderThreadId: null },
82
+ runs,
83
+ messages: [],
84
+ providerThreads: [],
85
+ providerSessions: [
86
+ {
87
+ id: "session",
88
+ status: "running",
89
+ capabilities: { turns: { supportsActiveSteering: true } },
90
+ },
91
+ ],
92
+ providerTurns: runs.flatMap((run) =>
93
+ run.activeAttemptId
94
+ ? [{ runAttemptId: run.activeAttemptId, status: "running" }]
95
+ : [],
96
+ ),
97
+ },
98
+ };
99
}),
100
},
101
environmentThreadShells: {
@@ -151,6 +177,7 @@ function view(
177
178
function setup() {
179
mocks.editQueuedRun.mockReset();
180
+ mocks.promoteQueuedRun.mockReset();
181
useAttachmentUploadStore.setState({ uploadsByImageId: {} });
182
useComposerDraftStore.setState({ draftsByThreadKey: {}, draftThreadsByThreadKey: {} });
183
setRuns(THREAD_A, "queued");
@@ -247,6 +274,42 @@ describe("useQueuedRunEdit", () => {
274
},
275
);
276
277
+ it.each([
278
+ // Cmd+Enter or Cmd-click with Queue as the default: save, then steer.
279
+ { dispatchMode: "steer", submissionIntent: "alternate", steers: true },
280
+ // Enter or the Update button with Steer as the default: save in place only.
281
+ { dispatchMode: "steer", submissionIntent: "foreground", steers: false },
282
+ // Cmd+Enter with Steer as the default queues, so the message stays queued.
283
+ { dispatchMode: "queue", submissionIntent: "alternate", steers: false },
284
+ ] as const)(
285
+ "a saved edit sent as $submissionIntent/$dispatchMode steers: $steers",
286
+ async (submission) => {
287
+ const { hook } = setup();
288
+ mocks.editQueuedRun.mockResolvedValue({ _tag: "Success" });
289
+ mocks.promoteQueuedRun.mockResolvedValue({ _tag: "Success" });
290
+ const activeRun = RunId.make("run-active");
291
+ appAtomRegistry.set(mocks.threadRuns(runsKey(THREAD_A)), [
292
+ { id: activeRun, status: "running", activeAttemptId: "attempt-1" },
293
+ { id: RUN, status: "queued" },
294
+ ]);
295
+ await using _screen = await render(view(THREAD_A, "queued", hook));
296
+ await beginChangedEdit(hook);
297
+ await act(() => requireHook(hook).saveEdit(savedContent("changed"), () => {}, submission));
298
+ expect(mocks.editQueuedRun).toHaveBeenCalledOnce();
299
+ if (!submission.steers) {
300
+ expect(mocks.promoteQueuedRun).not.toHaveBeenCalled();
301
+ return;
302
+ }
303
+ expect(mocks.promoteQueuedRun).toHaveBeenCalledExactlyOnceWith({
304
+ environmentId: ENV,
305
+ input: { threadId: THREAD_A.threadId, queuedRunId: RUN, targetRunId: activeRun },
306
+ });
307
+ expect(mocks.editQueuedRun.mock.invocationCallOrder[0]).toBeLessThan(
308
+ mocks.promoteQueuedRun.mock.invocationCallOrder[0]!,
309
+ );
310
+ },
311
+ );
312
+
313
it("saves an effort-only prompt without claiming removed attachments remain", async () => {
314
const { hook } = setup();
315
mocks.editQueuedRun.mockResolvedValue({ _tag: "Success" });
apps/web/src/components/chat/useQueuedRunEdit.ts
+39
@@ -3,7 +3,9 @@ import {
3
makeQueuedRunEditStore,
4
makeQueuedRunsAtom,
5
} from "@t3tools/client-runtime/queued-run-edit";
6
+import type { ComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch";
7
import type { ThreadStructure } from "@t3tools/client-runtime/state/shell";
8
+import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows";
9
import {
10
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
11
type ChatAttachment,
@@ -49,6 +51,7 @@ import {
51
} from "../../lib/composerContextReferences";
52
import { readFileAsDataUrl } from "../../lib/imageCompression";
53
import type { TerminalContextDraft } from "../../lib/terminalContext";
54
+import type { ComposerSubmissionIntent } from "../../composer-logic";
55
import type { ReviewCommentContext } from "../../reviewCommentContext";
56
import { appAtomRegistry } from "../../rpc/atomRegistry";
57
import { environmentServerConfigsAtom } from "../../state/server";
@@ -217,6 +220,7 @@ export function useQueuedRunEdit(input: {
220
composerRef,
221
} = input;
222
const editQueuedRunCommand = useEditQueuedRunCommand();
223
+ const promoteQueuedRun = useAtomCommand(threadEnvironment.promoteQueuedRun);
224
const editKey = scopedThreadKey(routeThreadRef);
225
const storedEdit = useAtomValue(queuedRunEdits.atom)[editKey] ?? null;
226
const editing = activeThreadId === null ? null : storedEdit;
@@ -343,9 +347,39 @@ export function useQueuedRunEdit(input: {
347
}));
348
});
349
350
+ // The same move as the queued row's "Send now" while a turn runs.
351
+ const steerSavedRun = async (edited: EditingQueuedRun) => {
352
+ const projection = appAtomRegistry.get(
353
+ environmentThreadDetails.quietThreadAtom({ environmentId, threadId: edited.threadId }),
354
+ )?.projection;
355
+ if (!projection) return;
356
+ const workflow = deriveThreadQueueWorkflowState(projection);
357
+ const queued = workflow.queuedRuns.find(({ run }) => run.id === edited.runId);
358
+ if (
359
+ queued === undefined ||
360
+ workflow.activeRun === null ||
361
+ !workflow.canPromoteToSteer ||
362
+ (queued.run.freshContext === true && !workflow.promoteSkipsCompaction)
363
+ ) {
364
+ return;
365
+ }
366
+ await promoteQueuedRun({
367
+ environmentId,
368
+ input: {
369
+ threadId: edited.threadId,
370
+ queuedRunId: edited.runId,
371
+ targetRunId: workflow.activeRun.id,
372
+ },
373
+ });
374
+ };
375
+
376
const saveEdit = async (
377
content: QueuedRunEditContent,
378
setThreadError: (threadId: ThreadId, error: string | null) => void,
379
+ submission?: {
380
+ readonly dispatchMode: ComposerDispatchMode;
381
+ readonly submissionIntent: ComposerSubmissionIntent;
382
+ },
383
) => {
384
if (editing === null || isSaving) return;
385
const newAttachments = [...content.images, ...content.files];
@@ -420,6 +454,11 @@ export function useQueuedRunEdit(input: {
454
clearEditDraft(editing.runId);
455
composerRef.current?.resetCursorState();
456
focusComposerSoon();
457
+ // A plain submit means "Update queued message"; only the opposite-action shortcut or
458
+ // modifier-click asks to steer, as it does for a new follow-up.
459
+ if (submission?.submissionIntent === "alternate" && submission.dispatchMode === "steer") {
460
+ await steerSavedRun(editing);
461
+ }
462
};
463
464
return {