Skip to content

Commit b9d94d9

Browse files
radroidclaude
andcommitted
feat(web): steer a running turn instead of queuing behind it (#35)
Typing while the agent works should reach the agent, the way it does in the Claude Code CLI. It already could: upstream's `onSend` has no `phase === "running"` guard, the decider has no running-turn invariant, and every adapter but Codex folds a mid-turn `sendTurn` into the live turn rather than opening a competing one — ClaudeAdapter.ts:3729 offers the message straight into the one long-lived `query()` whose prompt is a stream, which is the same stdin the CLI uses. Upstream even has a test for it (ClaudeAdapter.test.ts:976) and client-side handling to acknowledge a steering message (ChatView.logic.ts:537). The fork's outbox took that away. `resolveComposerSendLabel` returned "Queue" whenever the thread was busy, so `onSend`'s queue branch ran before upstream's immediate-send path and a message typed mid-turn waited out the entire turn — and, because `canSettle` also refuses while an approval is pending, sometimes much longer. Queue now means "cannot go out now" rather than "the thread is busy": - Not connected — still queues; nothing can be dispatched. - Outbox already has messages — still queues, so a new message cannot jump ahead of ones written before it. - Running turn on a steer-capable driver — sends, and the provider folds it into the work in progress. Steering support is an allowlist, not a denylist, because there is no capability flag anywhere in the contracts: `ProviderAdapterCapabilities` has no `supportsSteering`, so it is asserted per driver against each adapter's `sendTurn`. Claude, Cursor, Grok and OpenCode steer, three of them with tests. Codex does not — CodexSessionRuntime.ts:1305 issues `turn/start` unconditionally and never calls the protocol's `turn/steer` RPC — so it keeps queuing, as does any driver added later. Failing closed matters here because a refused steer is invisible: `providerService.sendTurn` is `Effect.forkScoped` (ProviderCommandReactor.ts:1110), so the command has already succeeded and the only trace is a `provider.turn.start.failed` activity. Failing closed costs a queued message; failing open loses one. The running-turn footer now pairs Stop with whichever primary action applies — Queue when the message will be held, the ordinary Send when it will be steered. That is not only discoverability: Enter does not submit on a mobile viewport, so the button is the only mid-turn send affordance on a phone. Seam impact: `ChatView.tsx` +158/-1 → +168/-1 (risk 9540 → 10140) and `ComposerPrimaryActions.tsx` +71/-13 → +130/-64 (336 → 776, the bulk being upstream's send button hoisted to a variable so the running branch can reuse it); rows and header totals updated. The steer predicate itself lives in a new fork-owned file rather than inline, per the ledger's own guidance. Also records the allowlist as a logic mirror: nothing fails if upstream changes an adapter to stop steering, so those four `sendTurn` implementations need re-checking at every sync. Verified: 80 tests green, typecheck and lint clean. The steer-vs-queue decision and the allowlist are unit-tested; the driver slugs are checked against ClaudeDriver.ts:60 and ClaudeAdapter.ts:96. Not verified end-to-end against a live Claude turn — the sandbox environment has no Claude provider instance and its Codex OAuth is stale. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 5232995 commit b9d94d9

7 files changed

Lines changed: 327 additions & 106 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ import {
166166
import { newCommandId, newDraftId, newMessageId, newThreadId } from "~/lib/utils";
167167
import { resolveComposerSendLabel } from "~/outbox/composerSendLabel.logic";
168168
import { enqueueThreadOutboxMessage, useThreadOutboxQueue } from "~/outbox/threadOutbox";
169+
import { canSteerActiveThread } from "~/outbox/composerSteering.logic";
169170
import { ThreadOutboxQueueList } from "./chat/ThreadOutboxQueueList";
170171
import { getProviderModelCapabilities, resolveSelectableProvider } from "../providerModels";
171172
import { NO_PROVIDER_MODEL_SELECTION } from "../providerInstances";
@@ -2143,10 +2144,19 @@ function ChatViewContent(props: ChatViewProps) {
21432144
// enqueues instead of erroring, and the drain sends the head once settled.
21442145
const outboxQueue = useThreadOutboxQueue(activeThread?.environmentId ?? null, activeThreadId);
21452146
const composerActiveThreadBusy = phase === "running" || isSendBusy || isRevertingCheckpoint;
2147+
// A running turn is not on its own a reason to queue: steer-capable drivers
2148+
// fold a mid-turn send into the work in progress.
2149+
const composerCanSteerActiveThread = canSteerActiveThread({
2150+
phase,
2151+
isSendBusy,
2152+
isRevertingCheckpoint,
2153+
provider: selectedProvider,
2154+
});
21462155
const composerSendLabel = resolveComposerSendLabel({
21472156
connectionState: activeEnvironmentConnectionPhase,
21482157
activeThreadBusy: composerActiveThreadBusy,
21492158
queueCount: outboxQueue.length,
2159+
canSteerActiveThread: composerCanSteerActiveThread,
21502160
});
21512161
const composerQueueMode =
21522162
isServerThread &&

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,60 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
135135
</Button>
136136
);
137137

138+
const sendButton = (
139+
<button
140+
type="submit"
141+
className={cn(
142+
"relative isolate flex h-9 w-9 items-center justify-center overflow-hidden rounded-full text-primary-foreground shadow-xs transition-all duration-150 enabled:cursor-pointer enabled:inset-shadow-[0_1px_--theme(--color-white/16%)] hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none disabled:pointer-events-none disabled:opacity-30 disabled:shadow-none disabled:hover:scale-100 sm:h-8 sm:w-8",
143+
stageBackdropVariant
144+
? "bg-transparent enabled:shadow-black/24 enabled:hover:brightness-110"
145+
: "bg-primary/90 enabled:shadow-primary/24 hover:bg-primary",
146+
)}
147+
{...pointerFocusProps}
148+
disabled={
149+
isSendBusy ||
150+
isSendDisabled ||
151+
isConnecting ||
152+
isEnvironmentUnavailable ||
153+
!hasSendableContent
154+
}
155+
aria-label={
156+
isEnvironmentUnavailable
157+
? "Environment disconnected"
158+
: sendDisabledReason
159+
? sendDisabledReason
160+
: isConnecting
161+
? "Connecting"
162+
: isPreparingWorktree
163+
? "Preparing worktree"
164+
: isSendBusy
165+
? "Sending"
166+
: isRunning
167+
? "Send message to the running turn"
168+
: "Send message"
169+
}
170+
>
171+
{stageBackdropVariant ? (
172+
<span className="absolute inset-0 -z-10" aria-hidden="true">
173+
<StageBackdropButtonArt variant={stageBackdropVariant} />
174+
</span>
175+
) : null}
176+
{isConnecting || isSendBusy ? (
177+
<Spinner className="size-3.5" aria-hidden="true" />
178+
) : (
179+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
180+
<path
181+
d="M7 11.5V2.5M7 2.5L3 6.5M7 2.5L11 6.5"
182+
stroke="currentColor"
183+
strokeWidth="1.8"
184+
strokeLinecap="round"
185+
strokeLinejoin="round"
186+
/>
187+
</svg>
188+
)}
189+
</button>
190+
);
191+
138192
if (pendingAction) {
139193
return (
140194
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
@@ -187,13 +241,17 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
187241
}
188242

189243
if (isRunning) {
190-
// While the thread is busy, queuing (when available) becomes the primary
191-
// action and Stop moves beside it as a secondary control.
244+
// While the thread is busy the primary action moves beside Stop, which
245+
// drops to a secondary control. Which action it is depends on whether the
246+
// message can go out now: "Queue" when it will be held, or the ordinary
247+
// Send when the provider will steer it into the running turn. Rendering it
248+
// matters beyond discoverability — Enter does not submit on a mobile
249+
// viewport, so this button is the only mid-turn send affordance there.
192250
if (canQueue) {
193251
return (
194252
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
195253
{secondaryStopButton}
196-
{queueButton}
254+
{sendLabel === "Queue" ? queueButton : sendButton}
197255
</div>
198256
);
199257
}
@@ -260,55 +318,5 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
260318
return queueButton;
261319
}
262320

263-
return (
264-
<button
265-
type="submit"
266-
className={cn(
267-
"relative isolate flex h-9 w-9 items-center justify-center overflow-hidden rounded-full text-primary-foreground shadow-xs transition-all duration-150 enabled:cursor-pointer enabled:inset-shadow-[0_1px_--theme(--color-white/16%)] hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none disabled:pointer-events-none disabled:opacity-30 disabled:shadow-none disabled:hover:scale-100 sm:h-8 sm:w-8",
268-
stageBackdropVariant
269-
? "bg-transparent enabled:shadow-black/24 enabled:hover:brightness-110"
270-
: "bg-primary/90 enabled:shadow-primary/24 hover:bg-primary",
271-
)}
272-
{...pointerFocusProps}
273-
disabled={
274-
isSendBusy ||
275-
isSendDisabled ||
276-
isConnecting ||
277-
isEnvironmentUnavailable ||
278-
!hasSendableContent
279-
}
280-
aria-label={
281-
isEnvironmentUnavailable
282-
? "Environment disconnected"
283-
: sendDisabledReason
284-
? sendDisabledReason
285-
: isConnecting
286-
? "Connecting"
287-
: isPreparingWorktree
288-
? "Preparing worktree"
289-
: isSendBusy
290-
? "Sending"
291-
: "Send message"
292-
}
293-
>
294-
{stageBackdropVariant ? (
295-
<span className="absolute inset-0 -z-10" aria-hidden="true">
296-
<StageBackdropButtonArt variant={stageBackdropVariant} />
297-
</span>
298-
) : null}
299-
{isConnecting || isSendBusy ? (
300-
<Spinner className="size-3.5" aria-hidden="true" />
301-
) : (
302-
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
303-
<path
304-
d="M7 11.5V2.5M7 2.5L3 6.5M7 2.5L11 6.5"
305-
stroke="currentColor"
306-
strokeWidth="1.8"
307-
strokeLinecap="round"
308-
strokeLinejoin="round"
309-
/>
310-
</svg>
311-
)}
312-
</button>
313-
);
321+
return sendButton;
314322
});

‎apps/web/src/outbox/composerSendLabel.logic.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,56 @@ describe("resolveComposerSendLabel", () => {
1313
).toBe("Send");
1414
});
1515

16-
it("labels Queue while the active thread is busy", () => {
16+
it("labels Queue while the active thread is busy and cannot be steered", () => {
1717
expect(
1818
resolveComposerSendLabel({
1919
connectionState: "connected",
2020
activeThreadBusy: true,
2121
queueCount: 0,
2222
}),
2323
).toBe("Queue");
24+
expect(
25+
resolveComposerSendLabel({
26+
connectionState: "connected",
27+
activeThreadBusy: true,
28+
queueCount: 0,
29+
canSteerActiveThread: false,
30+
}),
31+
).toBe("Queue");
32+
});
33+
34+
it("labels Send into a running turn the provider can steer", () => {
35+
expect(
36+
resolveComposerSendLabel({
37+
connectionState: "connected",
38+
activeThreadBusy: true,
39+
queueCount: 0,
40+
canSteerActiveThread: true,
41+
}),
42+
).toBe("Send");
43+
});
44+
45+
it("still queues a steerable thread when the outbox already holds messages", () => {
46+
// Steering would deliver this message ahead of ones queued before it.
47+
expect(
48+
resolveComposerSendLabel({
49+
connectionState: "connected",
50+
activeThreadBusy: true,
51+
queueCount: 1,
52+
canSteerActiveThread: true,
53+
}),
54+
).toBe("Queue");
55+
});
56+
57+
it("never steers while disconnected, however capable the provider is", () => {
58+
expect(
59+
resolveComposerSendLabel({
60+
connectionState: "reconnecting",
61+
activeThreadBusy: true,
62+
queueCount: 0,
63+
canSteerActiveThread: true,
64+
}),
65+
).toBe("Queue");
2466
});
2567

2668
it("labels Queue when messages are already queued to send later", () => {

‎apps/web/src/outbox/composerSendLabel.logic.ts‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
22

33
/**
4-
* Ported from apps/mobile/src/features/threads/composerSendLabel.ts.
4+
* Ported from apps/mobile/src/features/threads/composerSendLabel.ts, and since
5+
* diverged: web steers where mobile still queues (see `canSteerActiveThread`).
56
*
6-
* The composer's send affordance doubles as a queue affordance: every "send"
7-
* enqueues to the thread outbox, which sends-when-idle and holds-when-busy.
8-
* The button label mirrors that decision so the user knows whether pressing it
9-
* (or hitting Return) will dispatch now or queue for later.
7+
* The composer's send affordance doubles as a queue affordance. The button
8+
* label mirrors which one a submit will do, so the user knows whether pressing
9+
* it (or hitting Return) dispatches now or holds for later.
1010
*
11-
* Returns "Queue" when the message cannot be delivered immediately — the
12-
* environment is not connected, the active thread is still working, or the
13-
* outbox already holds messages — and "Send" only when it will go out now.
11+
* Returns "Queue" only when the message genuinely cannot go out now, and "Send"
12+
* whenever it will — including *into* a running turn, which the provider folds
13+
* into the work in progress.
1414
*/
1515
export function resolveComposerSendLabel(input: {
1616
readonly connectionState: EnvironmentConnectionPhase;
1717
readonly activeThreadBusy: boolean;
1818
readonly queueCount: number;
19+
/**
20+
* Whether the thread is busy in a way the provider can absorb right now —
21+
* i.e. a running turn on a steer-capable driver. A busy thread is not on its
22+
* own a reason to queue: the adapter folds a mid-turn send into the running
23+
* turn rather than opening a competing one. Omitted (or false) keeps the
24+
* original hold-while-busy behaviour.
25+
*/
26+
readonly canSteerActiveThread?: boolean;
1927
}): "Send" | "Queue" {
20-
if (input.connectionState !== "connected" || input.activeThreadBusy || input.queueCount > 0) {
28+
// Nothing can be dispatched without a connection.
29+
if (input.connectionState !== "connected") {
30+
return "Queue";
31+
}
32+
// Something is already waiting: sending now would jump the queue and deliver
33+
// this message ahead of ones the user wrote first.
34+
if (input.queueCount > 0) {
35+
return "Queue";
36+
}
37+
if (input.activeThreadBusy && input.canSteerActiveThread !== true) {
2138
return "Queue";
2239
}
2340
return "Send";
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { ProviderDriverKind } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { canSteerActiveThread, providerSupportsSteering } from "./composerSteering.logic";
5+
6+
describe("providerSupportsSteering", () => {
7+
it("allows the drivers whose adapters fold a mid-turn send into the running turn", () => {
8+
for (const driver of ["claudeAgent", "cursor", "grok", "opencode"]) {
9+
expect(providerSupportsSteering(ProviderDriverKind.make(driver))).toBe(true);
10+
}
11+
});
12+
13+
it("refuses codex, which always opens a turn rather than steering", () => {
14+
// CodexSessionRuntime issues `turn/start` unconditionally and overwrites
15+
// activeTurnId; the protocol's `turn/steer` RPC is never called.
16+
expect(providerSupportsSteering(ProviderDriverKind.make("codex"))).toBe(false);
17+
});
18+
19+
it("fails closed for an unknown or absent driver", () => {
20+
// An allowlist, not a denylist: a refused steer is invisible to the user
21+
// (the send command has already succeeded by the time the adapter refuses),
22+
// so an unrecognised driver must queue rather than risk losing a message.
23+
expect(providerSupportsSteering(ProviderDriverKind.make("some-future-driver"))).toBe(false);
24+
expect(providerSupportsSteering(null)).toBe(false);
25+
expect(providerSupportsSteering(undefined)).toBe(false);
26+
});
27+
});
28+
29+
describe("canSteerActiveThread", () => {
30+
const steerable = {
31+
phase: "running",
32+
isSendBusy: false,
33+
isRevertingCheckpoint: false,
34+
provider: ProviderDriverKind.make("claudeAgent"),
35+
};
36+
37+
it("steers a running turn on a capable provider", () => {
38+
expect(canSteerActiveThread(steerable)).toBe(true);
39+
});
40+
41+
it("does not steer a thread that is not running", () => {
42+
expect(canSteerActiveThread({ ...steerable, phase: "idle" })).toBe(false);
43+
});
44+
45+
it("does not steer while a local dispatch is still in flight", () => {
46+
// The immediate-send path bails on isSendBusy, so a submit here would be
47+
// dropped rather than sent; queuing keeps the message.
48+
expect(canSteerActiveThread({ ...steerable, isSendBusy: true })).toBe(false);
49+
});
50+
51+
it("does not steer while a checkpoint revert is in progress", () => {
52+
expect(canSteerActiveThread({ ...steerable, isRevertingCheckpoint: true })).toBe(false);
53+
});
54+
55+
it("does not steer a provider that opens a new turn instead", () => {
56+
expect(canSteerActiveThread({ ...steerable, provider: ProviderDriverKind.make("codex") })).toBe(
57+
false,
58+
);
59+
});
60+
});

0 commit comments

Comments
 (0)